####
Questions:
References:
Pooled Cross-sectional Data vs Panel Data Ask Michael about this if unclear
Survey weights
Data visualization
Working with codebooks
## here() starts at /Users/carriewright/Documents/GitHub/ocs-bloomberg-vaping-case-study
## ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.3.0 ──
## ✓ ggplot2 3.3.1 ✓ purrr 0.3.4
## ✓ tibble 3.0.1 ✓ dplyr 1.0.0
## ✓ tidyr 1.1.0 ✓ stringr 1.4.0
## ✓ readr 1.3.1 ✓ forcats 0.5.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
##
## Attaching package: 'srvyr'
## The following object is masked from 'package:stats':
##
## filter
##
## ********************************************************
## Note: As of version 1.0.0, cowplot does not change the
## default ggplot2 theme anymore. To recover the previous
## behavior, execute:
## theme_set(theme_cowplot())
## ********************************************************
## R version 4.0.1 (2020-06-06)
## Platform: x86_64-apple-darwin17.0 (64-bit)
## Running under: macOS Mojave 10.14.5
##
## Matrix products: default
## BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
## LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
##
## locale:
## [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] cowplot_1.0.0 srvyr_0.3.10 readxl_1.3.1 forcats_0.5.0
## [5] stringr_1.4.0 dplyr_1.0.0 purrr_0.3.4 readr_1.3.1
## [9] tidyr_1.1.0 tibble_3.0.1 ggplot2_3.3.1 tidyverse_1.3.0
## [13] here_0.1
##
## loaded via a namespace (and not attached):
## [1] tidyselect_1.1.0 xfun_0.14 mitools_2.4 splines_4.0.1
## [5] haven_2.3.1 lattice_0.20-41 colorspace_1.4-1 vctrs_0.3.0
## [9] generics_0.0.2 htmltools_0.4.0 yaml_2.2.1 survival_3.1-12
## [13] blob_1.2.1 rlang_0.4.6 pillar_1.4.4 glue_1.4.1
## [17] withr_2.2.0 DBI_1.1.0 dbplyr_1.4.4 modelr_0.1.8
## [21] lifecycle_0.2.0 munsell_0.5.0 gtable_0.3.0 cellranger_1.1.0
## [25] rvest_0.3.5 evaluate_0.14 knitr_1.28 fansi_0.4.1
## [29] broom_0.5.6 Rcpp_1.0.4.6 scales_1.1.1 backports_1.1.7
## [33] jsonlite_1.6.1 fs_1.4.1 hms_0.5.3 digest_0.6.25
## [37] stringi_1.4.6 survey_4.0 grid_4.0.1 rprojroot_1.3-2
## [41] cli_2.0.2 tools_4.0.1 magrittr_1.5 crayon_1.3.4
## [45] pkgconfig_2.0.3 Matrix_1.2-18 ellipsis_0.3.1 xml2_1.3.2
## [49] reprex_0.3.0 lubridate_1.7.8 assertthat_0.2.1 rmarkdown_2.2
## [53] httr_1.4.1 rstudioapi_0.11 R6_2.4.1 nlme_3.1-148
## [57] compiler_4.0.1
nyts_data[["nyts2015"]] <- nyts_data[["nyts2015"]] %>%
dplyr::select(psu,
finwgt,
stratum,
Qn1, #Age
Qn2, #Sex
Qn3, #Grade
starts_with("Qn4"), #Hispanic/Latino
starts_with("Qn5"), #Race
starts_with("E",
ignore.case = FALSE),
starts_with("C",
ignore.case = FALSE),
-EFLAVCIGTS,
-CFLAVCIGTS,
-EFLAVCIGAR,
) %>%
rename(Age=Qn1,
female=Qn2,
Grade=Qn3,
Not_HL=Qn4a,
HL_Mex=Qn4b,
HL_PR=Qn4c,
HL_Cub=Qn4d,
HL_Other=Qn4e,
Race_AIAN=Qn5a,
Race_Asian=Qn5b,
Race_BAA=Qn5c,
Race_NHOPI=Qn5d,
Race_White=Qn5e) %>%
mutate(Age=Age+8,
Grade=Grade+5,
brand_ecig=NA,
menthol=NA,
clove_spice=NA,
fruit=NA,
chocolate=NA,
alcoholic_drink=NA,
candy_dessert_sweets=NA,
other=NA,
no_use=NA) %>%
dplyr::select(-starts_with("Q"))## $psu
## 015438 058470 058688 073025 074170 086754 086998 087425 087656 087664 087896
## 313 325 221 232 314 347 93 336 397 470 437
## 087997 172374 172421 172817 172932 173042 173872 174438 215184 243985 244289
## 192 331 285 205 67 132 119 165 143 253 278
## 245271 245626 246502 259811 273721 302895 315630 343489 343499 344194 357949
## 345 36 110 211 254 223 116 259 156 348 251
## 358133 372861 373688 374028 374781 401600 401625 443836 457980 486439 486537
## 209 401 221 435 299 292 221 304 136 100 68
## 486665 487290 515976 515979 516124 516428 516479 516582 530234 530465 559544
## 320 204 169 219 230 130 166 280 249 279 234
## 559658 560204 572278 573191 586938 600437 602251 602538 657580 659775 673264
## 134 58 261 41 101 18 28 216 233 179 295
## 674219 674776 688472 689762 690405 692299 693273 700933 730119 730385 759375
## 170 194 96 137 49 65 176 231 275 313 205
## 772232 772340 787476 787705 789039
## 286 247 240 184 149
##
## $finwgt
## 6084.762382383 6084.749363267 6084.748763328 393.890426751 641.647375466
## 90 61 50 48 48
## 1462.436434424 593.037596627 895.030720016 342.509547149 934.989137039
## 47 45 44 37 37
## 702.57430816 645.096986799 6084.747889789 577.454052555 651.46204257
## 36 35 34 33 33
## 929.843069043 452.180288822 541.333365673 729.816382606 835.705455892
## 33 32 32 32 32
## 888.382540193 927.94099198 851.768379729 868.130099018 894.645660874
## 32 32 31 31 31
## 984.845596021 701.063606043 793.263666402 543.10044387 946.819967478
## 31 30 30 29 29
## 1015.462088582 1016.149108108 1019.981866234 1040.468408082 1141.362079889
## 29 29 29 29 29
## 1291.939451853 1329.790103112 182.06558616 743.973459478 794.640565906
## 29 29 28 28 28
## 898.543444732 1042.833088444 1131.481775528 1373.56145484 366.87804128
## 28 28 28 28 27
## 392.039206468 547.833907307 579.457069112 593.219832127 854.809873284
## 27 27 27 27 27
## 1048.47425302 1104.835457789 1159.516870486 1816.798230284 6054.100327083
## 27 27 27 27 27
## 606.95980431 818.085712533 1146.426800539 706.423256175 775.729833268
## 26 26 26 25 25
## 946.112967867 996.981564624 1025.880196581 1063.502080912 1119.667616736
## 25 25 25 25 25
## 1294.1057904 1315.317079036 6084.7477331 402.063366229 548.721336409
## 25 25 25 24 24
## 636.856583371 679.644603411 715.319618737 785.483271485 812.008313568
## 24 24 24 24 24
## 886.558267168 892.891330328 910.523814983 1034.181535833 1078.657221151
## 24 24 24 24 24
## 1342.832937151 1746.901437456 424.255231699 572.255680335 772.304638451
## 24 24 23 23 23
## 815.808021393 916.165629612 1166.771298082 1225.819285873 1322.399990435
## 23 23 23 23 23
## 1374.74354602 1673.993155958 1750.253995437 6036.818568997 660.0342283
## 23 23 23 23 22
## 695.66010798 705.225188396 760.691396806 793.377847684 (Other)
## 22 22 22 22 14820
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 1907 1305 918 391 1738 616 578 144 2821 402 446 233 1875 1954 799 1584
##
## $Age
## 9 10 11 12 13 14 15 16 17 18 19 NA's
## 23 5 930 2454 2832 2735 2535 2440 2302 1251 135 69
##
## $female
## 1 2 NA's
## 8958 8622 131
##
## $Grade
## 6 7 8 9 10 11 12 13 NA's
## 2552 2845 2773 2512 2509 2282 2130 18 90
##
## $Not_HL
## 1 NA's
## 12311 5400
##
## $HL_Mex
## 1 NA's
## 2736 14975
##
## $HL_PR
## 1 NA's
## 536 17175
##
## $HL_Cub
## 1 NA's
## 261 17450
##
## $HL_Other
## 1 NA's
## 1638 16073
##
## $Race_AIAN
## 1 NA's
## 1152 16559
##
## $Race_Asian
## 1 NA's
## 1023 16688
##
## $Race_BAA
## 1 NA's
## 3600 14111
##
## $Race_NHOPI
## 1 NA's
## 493 17218
##
## $Race_White
## 1 NA's
## 10853 6858
##
## $ECIGT
## 1 2 NA's
## 3713 13681 317
##
## $ECIGAR
## 1 2 NA's
## 2918 14379 414
##
## $ESLT
## 1 2 NA's
## 1360 15993 358
##
## $EELCIGT
## 1 2 NA's
## 4673 12727 311
##
## $EROLLCIGTS
## 1 2 NA's
## 862 16134 715
##
## $EBIDIS
## 1 2 NA's
## 245 16751 715
##
## $EHOOKAH
## 1 2 NA's
## 2244 14752 715
##
## $EPIPE
## 1 2 NA's
## 408 16588 715
##
## $ESNUS
## 1 2 NA's
## 394 16602 715
##
## $EDISSOLV
## 1 2 NA's
## 133 16863 715
##
## $CCIGT
## 1 2 NA's
## 1081 16266 364
##
## $CCIGAR
## 1 2 NA's
## 1006 16162 543
##
## $CSLT
## 1 2 NA's
## 606 16777 328
##
## $CELCIGT
## 1 2 NA's
## 1956 15485 270
##
## $CROLLCIGTS
## 1 2 NA's
## 368 16576 767
##
## $CBIDIS
## 1 2 NA's
## 90 16854 767
##
## $CHOOKAH
## 1 2 NA's
## 860 16084 767
##
## $CPIPE
## 1 2 NA's
## 137 16807 767
##
## $CSNUS
## 1 2 NA's
## 148 16796 767
##
## $CDISSOLV
## 1 2 NA's
## 54 16890 767
##
## $brand_ecig
## NA's
## 17711
##
## $menthol
## NA's
## 17711
##
## $clove_spice
## NA's
## 17711
##
## $fruit
## NA's
## 17711
##
## $chocolate
## NA's
## 17711
##
## $alcoholic_drink
## NA's
## 17711
##
## $candy_dessert_sweets
## NA's
## 17711
##
## $other
## NA's
## 17711
##
## $no_use
## NA's
## 17711
#Note about difference between recode and fct_recode
nyts_data[["nyts2015"]] <- nyts_data[["nyts2015"]] %>%
mutate_all(~ replace(., . %in% c("."), NA)) %>%
mutate(Age=as.character(Age),
Grade=as.character(Grade)
) %>%
mutate(Age=recode(Age,
`19` = ">18",
),
female=recode(female,
`1`= FALSE,
`2` = TRUE,
.default = NA,
.missing = NA),
Grade=recode(Grade,
`13` = "Ungraded/Other"),
Not_HL=recode(Not_HL,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)) %>%
mutate_at(vars(starts_with("HL", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("Race", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("E", ignore.case = FALSE),
starts_with("C", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
`2` = FALSE,
.default = NA,
.missing = NA)))## $psu
## 015438 058470 058688 073025 074170 086754 086998 087425 087656 087664 087896
## 313 325 221 232 314 347 93 336 397 470 437
## 087997 172374 172421 172817 172932 173042 173872 174438 215184 243985 244289
## 192 331 285 205 67 132 119 165 143 253 278
## 245271 245626 246502 259811 273721 302895 315630 343489 343499 344194 357949
## 345 36 110 211 254 223 116 259 156 348 251
## 358133 372861 373688 374028 374781 401600 401625 443836 457980 486439 486537
## 209 401 221 435 299 292 221 304 136 100 68
## 486665 487290 515976 515979 516124 516428 516479 516582 530234 530465 559544
## 320 204 169 219 230 130 166 280 249 279 234
## 559658 560204 572278 573191 586938 600437 602251 602538 657580 659775 673264
## 134 58 261 41 101 18 28 216 233 179 295
## 674219 674776 688472 689762 690405 692299 693273 700933 730119 730385 759375
## 170 194 96 137 49 65 176 231 275 313 205
## 772232 772340 787476 787705 789039
## 286 247 240 184 149
##
## $finwgt
## 6084.762382383 6084.749363267 6084.748763328 393.890426751 641.647375466
## 90 61 50 48 48
## 1462.436434424 593.037596627 895.030720016 342.509547149 934.989137039
## 47 45 44 37 37
## 702.57430816 645.096986799 6084.747889789 577.454052555 651.46204257
## 36 35 34 33 33
## 929.843069043 452.180288822 541.333365673 729.816382606 835.705455892
## 33 32 32 32 32
## 888.382540193 927.94099198 851.768379729 868.130099018 894.645660874
## 32 32 31 31 31
## 984.845596021 701.063606043 793.263666402 543.10044387 946.819967478
## 31 30 30 29 29
## 1015.462088582 1016.149108108 1019.981866234 1040.468408082 1141.362079889
## 29 29 29 29 29
## 1291.939451853 1329.790103112 182.06558616 743.973459478 794.640565906
## 29 29 28 28 28
## 898.543444732 1042.833088444 1131.481775528 1373.56145484 366.87804128
## 28 28 28 28 27
## 392.039206468 547.833907307 579.457069112 593.219832127 854.809873284
## 27 27 27 27 27
## 1048.47425302 1104.835457789 1159.516870486 1816.798230284 6054.100327083
## 27 27 27 27 27
## 606.95980431 818.085712533 1146.426800539 706.423256175 775.729833268
## 26 26 26 25 25
## 946.112967867 996.981564624 1025.880196581 1063.502080912 1119.667616736
## 25 25 25 25 25
## 1294.1057904 1315.317079036 6084.7477331 402.063366229 548.721336409
## 25 25 25 24 24
## 636.856583371 679.644603411 715.319618737 785.483271485 812.008313568
## 24 24 24 24 24
## 886.558267168 892.891330328 910.523814983 1034.181535833 1078.657221151
## 24 24 24 24 24
## 1342.832937151 1746.901437456 424.255231699 572.255680335 772.304638451
## 24 24 23 23 23
## 815.808021393 916.165629612 1166.771298082 1225.819285873 1322.399990435
## 23 23 23 23 23
## 1374.74354602 1673.993155958 1750.253995437 6036.818568997 660.0342283
## 23 23 23 23 22
## 695.66010798 705.225188396 760.691396806 793.377847684 (Other)
## 22 22 22 22 14820
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 1907 1305 918 391 1738 616 578 144 2821 402 446 233 1875 1954 799 1584
##
## $Age
## >18 10 11 12 13 14 15 16 17 18 9 NA's
## 135 5 930 2454 2832 2735 2535 2440 2302 1251 23 69
##
## $female
## FALSE TRUE NA's
## 8958 8622 131
##
## $Grade
## 10 11 12 6 7
## 2509 2282 2130 2552 2845
## 8 9 Ungraded/Other NA's
## 2773 2512 18 90
##
## $Not_HL
## FALSE TRUE
## 5400 12311
##
## $HL_Mex
## FALSE TRUE
## 14975 2736
##
## $HL_PR
## FALSE TRUE
## 17175 536
##
## $HL_Cub
## FALSE TRUE
## 17450 261
##
## $HL_Other
## FALSE TRUE
## 16073 1638
##
## $Race_AIAN
## FALSE TRUE
## 16559 1152
##
## $Race_Asian
## FALSE TRUE
## 16688 1023
##
## $Race_BAA
## FALSE TRUE
## 14111 3600
##
## $Race_NHOPI
## FALSE TRUE
## 17218 493
##
## $Race_White
## FALSE TRUE
## 6858 10853
##
## $ECIGT
## FALSE TRUE NA's
## 13681 3713 317
##
## $ECIGAR
## FALSE TRUE NA's
## 14379 2918 414
##
## $ESLT
## FALSE TRUE NA's
## 15993 1360 358
##
## $EELCIGT
## FALSE TRUE NA's
## 12727 4673 311
##
## $EROLLCIGTS
## FALSE TRUE NA's
## 16134 862 715
##
## $EBIDIS
## FALSE TRUE NA's
## 16751 245 715
##
## $EHOOKAH
## FALSE TRUE NA's
## 14752 2244 715
##
## $EPIPE
## FALSE TRUE NA's
## 16588 408 715
##
## $ESNUS
## FALSE TRUE NA's
## 16602 394 715
##
## $EDISSOLV
## FALSE TRUE NA's
## 16863 133 715
##
## $CCIGT
## FALSE TRUE NA's
## 16266 1081 364
##
## $CCIGAR
## FALSE TRUE NA's
## 16162 1006 543
##
## $CSLT
## FALSE TRUE NA's
## 16777 606 328
##
## $CELCIGT
## FALSE TRUE NA's
## 15485 1956 270
##
## $CROLLCIGTS
## FALSE TRUE NA's
## 16576 368 767
##
## $CBIDIS
## FALSE TRUE NA's
## 16854 90 767
##
## $CHOOKAH
## FALSE TRUE NA's
## 16084 860 767
##
## $CPIPE
## FALSE TRUE NA's
## 16807 137 767
##
## $CSNUS
## FALSE TRUE NA's
## 16796 148 767
##
## $CDISSOLV
## FALSE TRUE NA's
## 16890 54 767
##
## $brand_ecig
## NA's
## 17711
##
## $menthol
## NA's
## 17711
##
## $clove_spice
## NA's
## 17711
##
## $fruit
## NA's
## 17711
##
## $chocolate
## NA's
## 17711
##
## $alcoholic_drink
## NA's
## 17711
##
## $candy_dessert_sweets
## NA's
## 17711
##
## $other
## NA's
## 17711
##
## $no_use
## NA's
## 17711
nyts_data[["nyts2016"]] <- nyts_data[["nyts2016"]] %>%
dplyr::select(psu,
finwgt,
stratum,
Q1, #Age
Q2, #Sex
Q3, #Grade
starts_with("Q4"), #Hispanic/Latino
starts_with("Q5"), #Race
starts_with("E",
ignore.case = FALSE),
starts_with("C",
ignore.case = FALSE),
-EFLAVCIGAR,
Q50A, #Menthol # What flavors of tobacco products have you used in the past 30 days? (Select one or more)
Q50B, #Clove or spice
Q50C, #Fruit
Q50D, #Chocolate
Q50E, #Alcoholic Drink
Q50F, #Candy/Desserts/Other Sweets
Q50G, #Some Other Flavor Not Listed Here
Q50H #I Did Not Use Flavored Tobacco Products In the Past
) %>%
rename(Age=Q1,
female=Q2,
Grade=Q3,
Not_HL=Q4A,
HL_Mex=Q4B,
HL_PR=Q4C,
HL_Cub=Q4D,
HL_Other=Q4E,
Race_AIAN=Q5A,
Race_Asian=Q5B,
Race_BAA=Q5C,
Race_NHOPI=Q5D,
Race_White=Q5E,
female=Q2,
menthol=Q50A,
clove_spice=Q50B,
fruit=Q50C,
chocolate=Q50D,
alcoholic_drink=Q50E,
candy_dessert_sweets=Q50F,
other=Q50G,
no_use=Q50H) %>%
mutate(Age = as.numeric(Age) + 8,
Grade = as.numeric(Grade) + 5,
brand_ecig=NA) %>%
dplyr::select(-starts_with("Q"))## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## $psu
## 073102 074571 086338 086458 086878 087003 087082 087577 087614 087717 087843
## 132 231 227 80 479 308 78 157 363 111 421
## 087995 129241 172513 172966 173458 173584 173678 187262 187681 187822 188489
## 286 236 31 177 322 469 305 103 379 565 369
## 229430 243383 243436 244656 245190 246395 258577 258711 258847 273327 286879
## 235 109 248 88 200 181 161 350 64 130 83
## 300946 314704 314939 316875 329285 344685 372465 373302 373824 388878 400915
## 336 105 323 165 228 210 367 501 245 231 309
## 415525 416045 458137 486124 486487 486627 514830 515814 515921 516441 529391
## 277 371 452 318 133 251 344 450 256 132 333
## 530915 557654 560847 572477 587266 587583 600628 601255 603284 644416 644656
## 130 111 309 328 306 140 258 101 167 304 354
## 673286 687909 688620 689327 689334 689463 690874 692321 692498 701278 731503
## 308 436 221 368 229 165 157 133 301 144 414
## 758261 758520 758580 773513 787566
## 373 373 165 208 157
##
## $finwgt
## 871.325553937 1294.137423906 1438.420759833 480.328096721 1836.652739308
## 52 44 44 39 37
## 460.564361052 688.756981919 376.209171932 967.677487198 321.964869964
## 36 35 34 33 31
## 348.981595173 473.352544161 688.65484377 903.144043691 550.786275093
## 31 31 31 31 30
## 565.667360783 376.294559675 409.581862696 655.970957179 801.149846011
## 30 29 29 29 29
## 498.103814457 505.529262349 644.407869578 675.378921273 1605.713123985
## 28 28 28 28 28
## 184.169787561 426.971622861 600.026114872 858.33511763 873.5009733
## 27 27 27 27 27
## 904.585522134 1021.75047314 1709.767600953 225.718687325 419.223596249
## 27 27 27 26 26
## 512.349969836 517.86340288 718.983714005 898.62053191 78.392010249
## 26 26 26 26 25
## 646.941982176 812.140722555 1126.021341565 1199.777295284 1366.024060394
## 25 25 25 25 25
## 87.913448816 133.016213317 279.688771464 467.702830527 523.431999531
## 24 24 24 24 24
## 567.324960779 620.558359876 632.341563731 964.27945255 980.937057493
## 24 24 24 24 24
## 1039.842033152 1112.446942177 1317.836310254 1801.351760923 5924.173597737
## 24 24 24 24 24
## 526.09022941 1025.295175524 1594.189712455 2145.451026673 148.779868992
## 23 23 23 23 22
## 303.773166351 305.557190486 527.228440322 549.782141174 564.779037412
## 22 22 22 22 22
## 618.335209489 734.04886439 768.310439897 779.967411109 930.560748317
## 22 22 22 22 22
## 937.586106872 953.254427428 1001.9600149 1282.567263427 1387.558103013
## 22 22 22 22 22
## 1578.327459457 5924.05941567 173.430526483 367.733687159 390.275834436
## 22 22 21 21 21
## 408.817821295 413.505336139 414.400979608 454.575264221 528.344027409
## 21 21 21 21 21
## 556.197272634 647.322112608 665.201650109 699.029992183 730.643402941
## 21 21 21 21 21
## 841.459471942 886.34862584 912.379281326 947.907438733 (Other)
## 21 21 21 21 18123
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 1938 1300 780 627 1756 989 509 775 2906 705 433 386 2027 1906 1975 1663
##
## $Age
## 9 10 11 12 13 14 15 16 17 18 19 NA's
## 46 8 1297 2968 3195 3082 2785 2865 2681 1490 162 96
##
## $female
## 1 2 NA's
## 10438 10082 155
##
## $Grade
## 6 7 8 9 10 11 12 13 NA's
## 3235 3249 3174 2741 2809 2674 2673 16 104
##
## $Not_HL
## 1 NA's
## 14202 6473
##
## $HL_Mex
## 1 NA's
## 3091 17584
##
## $HL_PR
## 1 NA's
## 732 19943
##
## $HL_Cub
## 1 NA's
## 190 20485
##
## $HL_Other
## 1 NA's
## 2163 18512
##
## $Race_AIAN
## 1 NA's
## 1752 18923
##
## $Race_Asian
## 1 NA's
## 1567 19108
##
## $Race_BAA
## 1 NA's
## 4607 16068
##
## $Race_NHOPI
## 1 NA's
## 688 19987
##
## $Race_White
## 1 NA's
## 11661 9014
##
## $menthol
## 1 NA's
## 833 19842
##
## $clove_spice
## 1 NA's
## 113 20562
##
## $fruit
## 1 NA's
## 1109 19566
##
## $chocolate
## 1 NA's
## 230 20445
##
## $alcoholic_drink
## 1 NA's
## 310 20365
##
## $candy_dessert_sweets
## 1 NA's
## 700 19975
##
## $other
## 1 NA's
## 505 20170
##
## $no_use
## 1 NA's
## 17877 2798
##
## $ECIGT
## 1 2 NA's
## 3866 16376 433
##
## $ECIGAR
## 1 2 NA's
## 3154 17082 439
##
## $ESLT
## 1 2 NA's
## 1337 18873 465
##
## $EELCIGT
## 1 2 NA's
## 4485 15801 389
##
## $EHOOKAH
## 1 2 NA's
## 2140 17846 689
##
## $EROLLCIGTS
## 1 2 NA's
## 970 18931 774
##
## $EPIPE
## 1 2 NA's
## 467 19434 774
##
## $ESNUS
## 1 2 NA's
## 650 19251 774
##
## $EDISSOLV
## 1 2 NA's
## 219 19682 774
##
## $EBIDIS
## 1 2 NA's
## 184 19717 774
##
## $CCIGT
## 1 2 NA's
## 977 19215 483
##
## $CCIGAR
## 1 2 NA's
## 1049 19193 433
##
## $CSLT
## 1 2 NA's
## 526 19671 478
##
## $CELCIGT
## 1 2 NA's
## 1514 18752 409
##
## $CHOOKAH
## 1 2 NA's
## 733 19230 712
##
## $CROLLCIGTS
## 1 2 NA's
## 481 19371 823
##
## $CPIPE
## 1 2 NA's
## 214 19638 823
##
## $CSNUS
## 1 2 NA's
## 280 19572 823
##
## $CDISSOLV
## 1 2 NA's
## 132 19720 823
##
## $CBIDIS
## 1 2 NA's
## 97 19755 823
##
## $brand_ecig
## NA's
## 20675
nyts_data[["nyts2016"]] <- nyts_data[["nyts2016"]] %>%
mutate_all(~ replace(., . %in% c("*", "**"), NA)) %>%
mutate(Age=as.character(Age),
Grade=as.character(Grade)
) %>%
mutate(Age=recode(Age,
`19` = ">18",
),
female=recode(female,
`1`= FALSE,
`2` = TRUE,
.default = NA,
.missing = NA),
Grade=recode(Grade,
`13` = "Ungraded/Other"),
Not_HL=recode(Not_HL,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)) %>%
mutate_at(vars(starts_with("HL", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("Race", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("E", ignore.case = FALSE),
starts_with("C", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
`2` = FALSE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(menthol:no_use),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)))
sapply(nyts_data[["nyts2016"]], function(x)
summary(
factor(x)
)
)## $psu
## 073102 074571 086338 086458 086878 087003 087082 087577 087614 087717 087843
## 132 231 227 80 479 308 78 157 363 111 421
## 087995 129241 172513 172966 173458 173584 173678 187262 187681 187822 188489
## 286 236 31 177 322 469 305 103 379 565 369
## 229430 243383 243436 244656 245190 246395 258577 258711 258847 273327 286879
## 235 109 248 88 200 181 161 350 64 130 83
## 300946 314704 314939 316875 329285 344685 372465 373302 373824 388878 400915
## 336 105 323 165 228 210 367 501 245 231 309
## 415525 416045 458137 486124 486487 486627 514830 515814 515921 516441 529391
## 277 371 452 318 133 251 344 450 256 132 333
## 530915 557654 560847 572477 587266 587583 600628 601255 603284 644416 644656
## 130 111 309 328 306 140 258 101 167 304 354
## 673286 687909 688620 689327 689334 689463 690874 692321 692498 701278 731503
## 308 436 221 368 229 165 157 133 301 144 414
## 758261 758520 758580 773513 787566
## 373 373 165 208 157
##
## $finwgt
## 871.325553937 1294.137423906 1438.420759833 480.328096721 1836.652739308
## 52 44 44 39 37
## 460.564361052 688.756981919 376.209171932 967.677487198 321.964869964
## 36 35 34 33 31
## 348.981595173 473.352544161 688.65484377 903.144043691 550.786275093
## 31 31 31 31 30
## 565.667360783 376.294559675 409.581862696 655.970957179 801.149846011
## 30 29 29 29 29
## 498.103814457 505.529262349 644.407869578 675.378921273 1605.713123985
## 28 28 28 28 28
## 184.169787561 426.971622861 600.026114872 858.33511763 873.5009733
## 27 27 27 27 27
## 904.585522134 1021.75047314 1709.767600953 225.718687325 419.223596249
## 27 27 27 26 26
## 512.349969836 517.86340288 718.983714005 898.62053191 78.392010249
## 26 26 26 26 25
## 646.941982176 812.140722555 1126.021341565 1199.777295284 1366.024060394
## 25 25 25 25 25
## 87.913448816 133.016213317 279.688771464 467.702830527 523.431999531
## 24 24 24 24 24
## 567.324960779 620.558359876 632.341563731 964.27945255 980.937057493
## 24 24 24 24 24
## 1039.842033152 1112.446942177 1317.836310254 1801.351760923 5924.173597737
## 24 24 24 24 24
## 526.09022941 1025.295175524 1594.189712455 2145.451026673 148.779868992
## 23 23 23 23 22
## 303.773166351 305.557190486 527.228440322 549.782141174 564.779037412
## 22 22 22 22 22
## 618.335209489 734.04886439 768.310439897 779.967411109 930.560748317
## 22 22 22 22 22
## 937.586106872 953.254427428 1001.9600149 1282.567263427 1387.558103013
## 22 22 22 22 22
## 1578.327459457 5924.05941567 173.430526483 367.733687159 390.275834436
## 22 22 21 21 21
## 408.817821295 413.505336139 414.400979608 454.575264221 528.344027409
## 21 21 21 21 21
## 556.197272634 647.322112608 665.201650109 699.029992183 730.643402941
## 21 21 21 21 21
## 841.459471942 886.34862584 912.379281326 947.907438733 (Other)
## 21 21 21 21 18123
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 1938 1300 780 627 1756 989 509 775 2906 705 433 386 2027 1906 1975 1663
##
## $Age
## >18 10 11 12 13 14 15 16 17 18 9 NA's
## 162 8 1297 2968 3195 3082 2785 2865 2681 1490 46 96
##
## $female
## FALSE TRUE NA's
## 10438 10082 155
##
## $Grade
## 10 11 12 6 7
## 2809 2674 2673 3235 3249
## 8 9 Ungraded/Other NA's
## 3174 2741 16 104
##
## $Not_HL
## FALSE TRUE
## 6473 14202
##
## $HL_Mex
## FALSE TRUE
## 17584 3091
##
## $HL_PR
## FALSE TRUE
## 19943 732
##
## $HL_Cub
## FALSE TRUE
## 20485 190
##
## $HL_Other
## FALSE TRUE
## 18512 2163
##
## $Race_AIAN
## FALSE TRUE
## 18923 1752
##
## $Race_Asian
## FALSE TRUE
## 19108 1567
##
## $Race_BAA
## FALSE TRUE
## 16068 4607
##
## $Race_NHOPI
## FALSE TRUE
## 19987 688
##
## $Race_White
## FALSE TRUE
## 9014 11661
##
## $menthol
## FALSE TRUE
## 19842 833
##
## $clove_spice
## FALSE TRUE
## 20562 113
##
## $fruit
## FALSE TRUE
## 19566 1109
##
## $chocolate
## FALSE TRUE
## 20445 230
##
## $alcoholic_drink
## FALSE TRUE
## 20365 310
##
## $candy_dessert_sweets
## FALSE TRUE
## 19975 700
##
## $other
## FALSE TRUE
## 20170 505
##
## $no_use
## FALSE TRUE
## 2798 17877
##
## $ECIGT
## FALSE TRUE
## 16809 3866
##
## $ECIGAR
## FALSE TRUE
## 17521 3154
##
## $ESLT
## FALSE TRUE
## 19338 1337
##
## $EELCIGT
## FALSE TRUE
## 16190 4485
##
## $EHOOKAH
## FALSE TRUE
## 18535 2140
##
## $EROLLCIGTS
## FALSE TRUE
## 19705 970
##
## $EPIPE
## FALSE TRUE
## 20208 467
##
## $ESNUS
## FALSE TRUE
## 20025 650
##
## $EDISSOLV
## FALSE TRUE
## 20456 219
##
## $EBIDIS
## FALSE TRUE
## 20491 184
##
## $CCIGT
## FALSE TRUE
## 19698 977
##
## $CCIGAR
## FALSE TRUE
## 19626 1049
##
## $CSLT
## FALSE TRUE
## 20149 526
##
## $CELCIGT
## FALSE TRUE
## 19161 1514
##
## $CHOOKAH
## FALSE TRUE
## 19942 733
##
## $CROLLCIGTS
## FALSE TRUE
## 20194 481
##
## $CPIPE
## FALSE TRUE
## 20461 214
##
## $CSNUS
## FALSE TRUE
## 20395 280
##
## $CDISSOLV
## FALSE TRUE
## 20543 132
##
## $CBIDIS
## FALSE TRUE
## 20578 97
##
## $brand_ecig
## NA's
## 20675
nyts_data[["nyts2017"]] <- nyts_data[["nyts2017"]] %>%
dplyr::select(psu,
finwgt,
stratum,
Q1, #Age
Q2, #Sex
Q3, #Grade
starts_with("Q4"), #Hispanic/Latino
starts_with("Q5"), #Race
starts_with("E",
ignore.case = FALSE),
starts_with("C",
ignore.case = FALSE),
CBIDIS,
Q50A, #Menthol # What flavors of tobacco products have you used in the past 30 days? (Select one or more)
Q50B, #Clove or spice
Q50C, #Fruit
Q50D, #Chocolate
Q50E, #Alcoholic Drink
Q50F, #Candy/Desserts/Other Sweets
Q50G, #Some Other Flavor Not Listed Here
Q50H #I Did Not Use Flavored Tobacco Products In the Past
) %>%
rename(Age=Q1,
female=Q2,
Grade=Q3,
Not_HL=Q4A,
HL_Mex=Q4B,
HL_PR=Q4C,
HL_Cub=Q4D,
HL_Other=Q4E,
Race_AIAN=Q5A,
Race_Asian=Q5B,
Race_BAA=Q5C,
Race_NHOPI=Q5D,
Race_White=Q5E,
female=Q2,
menthol=Q50A,
clove_spice=Q50B,
fruit=Q50C,
chocolate=Q50D,
alcoholic_drink=Q50E,
candy_dessert_sweets=Q50F,
other=Q50G,
no_use=Q50H) %>%
mutate(Age = as.numeric(Age) + 8,
Grade = as.numeric(Grade) + 5,
brand_ecig=NA) %>%
dplyr::select(-starts_with("Q"))## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## $psu
## 014595 058385 086452 086889 086972 087144 087174 087568 087858 088152 115262
## 354 165 296 240 268 188 314 318 93 129 278
## 129060 129751 142976 171594 173094 173711 174186 174258 186117 188113 188207
## 256 170 252 116 160 226 249 318 341 288 320
## 188307 243848 245033 258883 259591 259810 274380 301900 302266 314736 343581
## 421 134 148 140 274 167 189 188 309 370 213
## 343702 344106 344317 350305 373245 373427 374076 374456 387897 400362 401050
## 394 265 60 75 164 463 293 336 203 229 81
## 418326 487115 487123 501078 515682 515683 515792 515990 516100 516335 530582
## 193 182 37 240 257 68 208 364 172 189 379
## 558771 559447 559816 585762 586736 600815 602062 602173 602417 602425 644424
## 283 155 137 72 178 531 206 129 169 87 158
## 672182 674270 686434 686767 689716 690913 692424 692818 693010 701295 729632
## 205 174 138 32 276 185 421 217 34 168 285
## 730705 757723 758362 758663 772237
## 184 171 185 174 174
##
## $finwgt
## 388.086140156 471.940845283 390.583989416 405.380567077 472.183232467
## 51 49 48 48 47
## 724.56606859 1784.368053098 518.253252285 787.40156861 1058.307376853
## 35 35 33 32 31
## 6505.08401827 666.989424614 759.980607023 855.933815842 480.026932681
## 31 30 30 30 29
## 848.614920471 926.022139243 2054.047484589 199.574079216 398.046267884
## 29 29 29 28 28
## 632.528237732 265.565422115 434.241886925 479.524141762 603.41343573
## 28 27 27 27 27
## 2481.307388658 206.462147383 316.796633448 460.22386269 697.047119656
## 27 26 26 26 26
## 807.931561134 881.176565371 1277.075266177 208.231781084 446.05788661
## 26 26 26 25 25
## 491.359940944 543.904772031 826.431573503 1666.670226291 2107.763960713
## 25 25 25 25 25
## 160.937199594 212.899945196 372.505372275 715.045700881 867.20325432
## 24 24 24 24 24
## 994.573293824 1270.103663994 1369.362294624 131.733679461 393.994795267
## 24 24 24 23 23
## 409.742815639 506.068428826 649.586475366 833.801586236 1053.241357521
## 23 23 23 23 23
## 1075.316452245 1097.264887598 1472.297231462 2471.826577818 6505.083867486
## 23 23 23 23 23
## 100.878347987 168.013153338 380.795649055 469.240664401 538.7376444
## 22 22 22 22 22
## 564.525712854 605.326863684 631.400184035 734.054217019 974.402999538
## 22 22 22 22 22
## 1041.12052098 1113.839139761 1157.153752424 1717.302420506 244.503033338
## 22 22 22 22 21
## 291.475998553 320.204350521 322.837800152 410.491377261 565.365433905
## 21 21 21 21 21
## 845.653652239 865.290461476 931.797436444 1054.095980076 1063.980316558
## 21 21 21 21 21
## 1280.057483708 1527.232038241 6491.921224713 384.116284763 532.124703938
## 21 21 21 20 20
## 549.714915274 657.596180463 966.440787959 1161.610230855 1197.989688589
## 20 20 20 20 20
## 1278.78119818 1499.591207108 1747.734538876 1816.850159172 (Other)
## 20 20 20 20 15360
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 1865 968 1087 1021 1205 930 1318 711 2493 249 707 323 1546 1654 697 1098
##
## $Age
## 9 10 11 12 13 14 15 16 17 18 19 NA's
## 36 12 1018 2413 2495 2479 2704 2588 2525 1361 146 95
##
## $female
## 1 2 NA's
## 8881 8815 176
##
## $Grade
## 6 7 8 9 10 11 12 13 NA's
## 2524 2565 2473 2583 2637 2575 2391 25 99
##
## $Not_HL
## 1 NA's
## 12696 5176
##
## $HL_Mex
## 1 NA's
## 2190 15682
##
## $HL_PR
## 1 NA's
## 527 17345
##
## $HL_Cub
## 1 NA's
## 220 17652
##
## $HL_Other
## 1 NA's
## 1970 15902
##
## $Race_AIAN
## 1 NA's
## 1186 16686
##
## $Race_Asian
## 1 NA's
## 1216 16656
##
## $Race_BAA
## 1 NA's
## 4328 13544
##
## $Race_NHOPI
## 1 NA's
## 526 17346
##
## $Race_White
## 1 NA's
## 10478 7394
##
## $menthol
## 1 NA's
## 748 17124
##
## $clove_spice
## 1 NA's
## 89 17783
##
## $fruit
## 1 NA's
## 1024 16848
##
## $chocolate
## 1 NA's
## 203 17669
##
## $alcoholic_drink
## 1 NA's
## 321 17551
##
## $candy_dessert_sweets
## 1 NA's
## 620 17252
##
## $other
## 1 NA's
## 434 17438
##
## $no_use
## 1 NA's
## 15421 2451
##
## $ECIGT
## 1 2 NA's
## 3107 14433 332
##
## $ECIGAR
## 1 2 NA's
## 2495 14991 386
##
## $ESLT
## 1 2 NA's
## 1151 16277 444
##
## $EELCIGT
## 1 2 NA's
## 3695 13754 423
##
## $EHOOKAH
## 1 2 NA's
## 1456 16003 413
##
## $EROLLCIGTS
## 1 2 NA's
## 819 16517 536
##
## $EPIPE
## 1 2 NA's
## 361 16975 536
##
## $ESNUS
## 1 2 NA's
## 648 16688 536
##
## $EDISSOLV
## 1 2 NA's
## 229 17107 536
##
## $EBIDIS
## 1 2 NA's
## 232 17104 536
##
## $CCIGT
## 1 2 NA's
## 973 16461 438
##
## $CCIGAR
## 1 2 NA's
## 977 16439 456
##
## $CSLT
## 1 2 NA's
## 510 16795 567
##
## $CELCIGT
## 1 2 NA's
## 1360 16210 302
##
## $CHOOKAH
## 1 2 NA's
## 508 16880 484
##
## $CROLLCIGTS
## 1 2 NA's
## 369 16959 544
##
## $CPIPE
## 1 2 NA's
## 137 17191 544
##
## $CSNUS
## 1 2 NA's
## 249 17079 544
##
## $CDISSOLV
## 1 2 NA's
## 105 17223 544
##
## $CBIDIS
## 1 2 NA's
## 105 17223 544
##
## $brand_ecig
## NA's
## 17872
nyts_data[["nyts2017"]] <- nyts_data[["nyts2017"]] %>%
mutate_all(~ replace(., . %in% c("*", "**"), NA)) %>%
mutate(Age=as.character(Age),
Grade=as.character(Grade)
) %>%
mutate(Age=recode(Age,
`19` = ">18",
),
female=recode(female,
`1`= FALSE,
`2` = TRUE,
.default = NA,
.missing = NA),
Grade=recode(Grade,
`13` = "Ungraded/Other"),
Not_HL=recode(Not_HL,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)) %>%
mutate_at(vars(starts_with("HL", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("Race", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("E", ignore.case = FALSE),
starts_with("C", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
`2` = FALSE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(menthol:no_use),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)))
sapply(nyts_data[["nyts2017"]], function(x)
summary(
factor(x)
)
)## $psu
## 014595 058385 086452 086889 086972 087144 087174 087568 087858 088152 115262
## 354 165 296 240 268 188 314 318 93 129 278
## 129060 129751 142976 171594 173094 173711 174186 174258 186117 188113 188207
## 256 170 252 116 160 226 249 318 341 288 320
## 188307 243848 245033 258883 259591 259810 274380 301900 302266 314736 343581
## 421 134 148 140 274 167 189 188 309 370 213
## 343702 344106 344317 350305 373245 373427 374076 374456 387897 400362 401050
## 394 265 60 75 164 463 293 336 203 229 81
## 418326 487115 487123 501078 515682 515683 515792 515990 516100 516335 530582
## 193 182 37 240 257 68 208 364 172 189 379
## 558771 559447 559816 585762 586736 600815 602062 602173 602417 602425 644424
## 283 155 137 72 178 531 206 129 169 87 158
## 672182 674270 686434 686767 689716 690913 692424 692818 693010 701295 729632
## 205 174 138 32 276 185 421 217 34 168 285
## 730705 757723 758362 758663 772237
## 184 171 185 174 174
##
## $finwgt
## 388.086140156 471.940845283 390.583989416 405.380567077 472.183232467
## 51 49 48 48 47
## 724.56606859 1784.368053098 518.253252285 787.40156861 1058.307376853
## 35 35 33 32 31
## 6505.08401827 666.989424614 759.980607023 855.933815842 480.026932681
## 31 30 30 30 29
## 848.614920471 926.022139243 2054.047484589 199.574079216 398.046267884
## 29 29 29 28 28
## 632.528237732 265.565422115 434.241886925 479.524141762 603.41343573
## 28 27 27 27 27
## 2481.307388658 206.462147383 316.796633448 460.22386269 697.047119656
## 27 26 26 26 26
## 807.931561134 881.176565371 1277.075266177 208.231781084 446.05788661
## 26 26 26 25 25
## 491.359940944 543.904772031 826.431573503 1666.670226291 2107.763960713
## 25 25 25 25 25
## 160.937199594 212.899945196 372.505372275 715.045700881 867.20325432
## 24 24 24 24 24
## 994.573293824 1270.103663994 1369.362294624 131.733679461 393.994795267
## 24 24 24 23 23
## 409.742815639 506.068428826 649.586475366 833.801586236 1053.241357521
## 23 23 23 23 23
## 1075.316452245 1097.264887598 1472.297231462 2471.826577818 6505.083867486
## 23 23 23 23 23
## 100.878347987 168.013153338 380.795649055 469.240664401 538.7376444
## 22 22 22 22 22
## 564.525712854 605.326863684 631.400184035 734.054217019 974.402999538
## 22 22 22 22 22
## 1041.12052098 1113.839139761 1157.153752424 1717.302420506 244.503033338
## 22 22 22 22 21
## 291.475998553 320.204350521 322.837800152 410.491377261 565.365433905
## 21 21 21 21 21
## 845.653652239 865.290461476 931.797436444 1054.095980076 1063.980316558
## 21 21 21 21 21
## 1280.057483708 1527.232038241 6491.921224713 384.116284763 532.124703938
## 21 21 21 20 20
## 549.714915274 657.596180463 966.440787959 1161.610230855 1197.989688589
## 20 20 20 20 20
## 1278.78119818 1499.591207108 1747.734538876 1816.850159172 (Other)
## 20 20 20 20 15360
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 1865 968 1087 1021 1205 930 1318 711 2493 249 707 323 1546 1654 697 1098
##
## $Age
## >18 10 11 12 13 14 15 16 17 18 9 NA's
## 146 12 1018 2413 2495 2479 2704 2588 2525 1361 36 95
##
## $female
## FALSE TRUE NA's
## 8881 8815 176
##
## $Grade
## 10 11 12 6 7
## 2637 2575 2391 2524 2565
## 8 9 Ungraded/Other NA's
## 2473 2583 25 99
##
## $Not_HL
## FALSE TRUE
## 5176 12696
##
## $HL_Mex
## FALSE TRUE
## 15682 2190
##
## $HL_PR
## FALSE TRUE
## 17345 527
##
## $HL_Cub
## FALSE TRUE
## 17652 220
##
## $HL_Other
## FALSE TRUE
## 15902 1970
##
## $Race_AIAN
## FALSE TRUE
## 16686 1186
##
## $Race_Asian
## FALSE TRUE
## 16656 1216
##
## $Race_BAA
## FALSE TRUE
## 13544 4328
##
## $Race_NHOPI
## FALSE TRUE
## 17346 526
##
## $Race_White
## FALSE TRUE
## 7394 10478
##
## $menthol
## FALSE TRUE
## 17124 748
##
## $clove_spice
## FALSE TRUE
## 17783 89
##
## $fruit
## FALSE TRUE
## 16848 1024
##
## $chocolate
## FALSE TRUE
## 17669 203
##
## $alcoholic_drink
## FALSE TRUE
## 17551 321
##
## $candy_dessert_sweets
## FALSE TRUE
## 17252 620
##
## $other
## FALSE TRUE
## 17438 434
##
## $no_use
## FALSE TRUE
## 2451 15421
##
## $ECIGT
## FALSE TRUE
## 14765 3107
##
## $ECIGAR
## FALSE TRUE
## 15377 2495
##
## $ESLT
## FALSE TRUE
## 16721 1151
##
## $EELCIGT
## FALSE TRUE
## 14177 3695
##
## $EHOOKAH
## FALSE TRUE
## 16416 1456
##
## $EROLLCIGTS
## FALSE TRUE
## 17053 819
##
## $EPIPE
## FALSE TRUE
## 17511 361
##
## $ESNUS
## FALSE TRUE
## 17224 648
##
## $EDISSOLV
## FALSE TRUE
## 17643 229
##
## $EBIDIS
## FALSE TRUE
## 17640 232
##
## $CCIGT
## FALSE TRUE
## 16899 973
##
## $CCIGAR
## FALSE TRUE
## 16895 977
##
## $CSLT
## FALSE TRUE
## 17362 510
##
## $CELCIGT
## FALSE TRUE
## 16512 1360
##
## $CHOOKAH
## FALSE TRUE
## 17364 508
##
## $CROLLCIGTS
## FALSE TRUE
## 17503 369
##
## $CPIPE
## FALSE TRUE
## 17735 137
##
## $CSNUS
## FALSE TRUE
## 17623 249
##
## $CDISSOLV
## FALSE TRUE
## 17767 105
##
## $CBIDIS
## FALSE TRUE
## 17767 105
##
## $brand_ecig
## NA's
## 17872
nyts_data[["nyts2018"]] <- nyts_data[["nyts2018"]] %>%
dplyr::select(psu,
finwgt,
stratum,
Q1, #Age
Q2, #Sex
Q3, #Grade
starts_with("Q4"), #Hispanic/Latino
starts_with("Q5"), #Race
starts_with("E",
ignore.case = FALSE),
starts_with("C",
ignore.case = FALSE),
Q50A, #Menthol # What flavors of tobacco products have you used in the past 30 days? (Select one or more)
Q50B, #Clove or spice
Q50C, #Fruit
Q50D, #Chocolate
Q50E, #Alcoholic Drink
Q50F, #Candy/Desserts/Other Sweets
Q50G, #Some Other Flavor Not Listed Here
Q50H #I Did Not Use Flavored Tobacco Products In the Past
) %>%
rename(Age=Q1,
female=Q2,
Grade=Q3,
Not_HL=Q4A,
HL_Mex=Q4B,
HL_PR=Q4C,
HL_Cub=Q4D,
HL_Other=Q4E,
Race_AIAN=Q5A,
Race_Asian=Q5B,
Race_BAA=Q5C,
Race_NHOPI=Q5D,
Race_White=Q5E,
female=Q2,
menthol=Q50A,
clove_spice=Q50B,
fruit=Q50C,
chocolate=Q50D,
alcoholic_drink=Q50E,
candy_dessert_sweets=Q50F,
other=Q50G,
no_use=Q50H) %>%
mutate(Age = as.numeric(Age) + 8,
Grade = as.numeric(Grade) + 5,
brand_ecig=NA) %>%
dplyr::select(-starts_with("Q"))## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## $psu
## 015659 057544 058063 058279 058342 086286 086582 086634 086775 086958 086993
## 131 83 241 231 177 223 54 288 250 84 216
## 087009 087143 087205 087214 087537 088258 088304 143354 144110 172268 172362
## 238 133 222 187 183 270 72 372 307 214 249
## 172827 173483 173518 173614 187069 187695 188339 188792 188841 190174 243742
## 192 368 373 155 252 15 383 156 382 368 344
## 243772 244646 245531 245863 246106 258141 259259 259407 273856 303189 314614
## 171 148 320 300 116 84 86 148 61 274 264
## 315356 315841 316022 344472 357756 371868 372907 373105 374569 387227 388116
## 301 317 364 319 166 59 195 317 166 322 25
## 415354 415942 457785 458247 472607 486733 487266 500919 514921 516648 529004
## 134 64 213 182 103 78 166 83 64 165 284
## 529849 559574 559658 572256 600729 601533 601983 602020 603179 629054 644674
## 352 312 197 417 290 406 374 45 71 161 328
## 672288 673839 674805 686156 687050 687585 687958 688552 689044 689416 689634
## 274 277 320 119 126 90 144 303 264 86 305
## 690574 692282 700978 701250 736480 757540 759020
## 182 253 125 15 394 235 252
##
## $finwgt
## 4990.707825052 372.106445056 374.223712424 438.895059192 512.773737505
## 73 54 53 53 50
## 4990.707824997 354.403367156 459.264157663 794.117545838 4990.707825184
## 46 38 38 35 35
## 261.594994077 604.212351194 464.262746508 526.352614715 243.614971982
## 34 34 33 31 30
## 716.756339454 1133.236763357 1063.013428506 499.309679476 725.642399133
## 30 30 29 28 28
## 955.117892997 533.302805442 878.385000967 884.736590151 615.101958781
## 28 27 27 27 26
## 656.112273243 763.304212486 772.024461398 804.949783275 436.289029717
## 26 26 26 26 25
## 1075.075363375 1116.00695267 1120.843771262 1208.191548298 1364.127973987
## 25 25 25 25 25
## 3176.705125185 359.909264221 501.302998165 639.387801493 672.915273738
## 25 24 24 24 24
## 750.014182644 768.617690322 772.265673267 872.656690614 925.421592037
## 24 24 24 24 24
## 925.454369278 934.553252225 997.238713858 1060.007709052 1921.985860852
## 24 24 24 24 24
## 4989.824123193 230.825021393 592.209826559 637.612536618 1173.734572865
## 24 23 23 23 23
## 1215.661901874 1397.810883406 1455.757503148 2086.599584044 4943.253945798
## 23 23 23 23 23
## 4965.403983968 358.261960805 610.908165514 643.867829284 662.274116541
## 23 22 22 22 22
## 755.668600945 792.397022445 890.114756698 1000.670065114 1121.902399257
## 22 22 22 22 22
## 1216.404436426 1484.57374707 1918.7838166 2132.519656006 285.715212581
## 22 22 22 22 21
## 435.458751085 488.084421785 502.351127283 546.319362206 601.212956081
## 21 21 21 21 21
## 635.885463139 662.109306082 753.224172586 757.829169717 809.249572869
## 21 21 21 21 21
## 847.008048039 966.525436209 1007.915531153 1060.586057955 1100.972041909
## 21 21 21 21 21
## 1167.285951387 1271.451496438 104.948041269 303.014353117 306.179881848
## 21 21 20 20 20
## 400.963911867 516.160638629 669.231249605 691.04417579 (Other)
## 20 20 20 20 17599
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 2346 1575 1170 621 1849 1114 548 742 2392 862 774 559 1731 1430 1160 1316
##
## $Age
## 9 10 11 12 13 14 15 16 17 18 19 NA's
## 58 6 1007 2875 3013 2930 2881 2789 2719 1630 162 119
##
## $female
## 1 2 NA's
## 10069 9920 200
##
## $Grade
## 6 7 8 9 10 11 12 13 NA's
## 2903 3140 3012 2935 2664 2824 2568 16 127
##
## $Not_HL
## 1 NA's
## 13766 6423
##
## $HL_Mex
## 1 NA's
## 3065 17124
##
## $HL_PR
## 1 NA's
## 657 19532
##
## $HL_Cub
## 1 NA's
## 345 19844
##
## $HL_Other
## 1 NA's
## 2102 18087
##
## $Race_AIAN
## 1 NA's
## 1592 18597
##
## $Race_Asian
## 1 NA's
## 1219 18970
##
## $Race_BAA
## 1 NA's
## 3836 16353
##
## $Race_NHOPI
## 1 NA's
## 577 19612
##
## $Race_White
## 1 NA's
## 12624 7565
##
## $menthol
## 1 NA's
## 1251 18938
##
## $clove_spice
## 1 NA's
## 104 20085
##
## $fruit
## 1 NA's
## 1789 18400
##
## $chocolate
## 1 NA's
## 249 19940
##
## $alcoholic_drink
## 1 NA's
## 364 19825
##
## $candy_dessert_sweets
## 1 NA's
## 1138 19051
##
## $other
## 1 NA's
## 755 19434
##
## $no_use
## 1 NA's
## 16605 3584
##
## $ECIGT
## 1 2 NA's
## 3559 16268 362
##
## $ECIGAR
## 1 2 NA's
## 2876 16831 482
##
## $ESLT
## 1 2 NA's
## 1444 18194 551
##
## $EELCIGT
## 1 2 NA's
## 5071 14572 546
##
## $EHOOKAH
## 1 2 NA's
## 1433 18239 517
##
## $EROLLCIGTS
## 1 2 NA's
## 953 18513 723
##
## $EPIPE
## 1 2 NA's
## 451 19015 723
##
## $ESNUS
## 1 2 NA's
## 837 18629 723
##
## $EDISSOLV
## 1 2 NA's
## 278 19188 723
##
## $EBIDIS
## 1 2 NA's
## 274 19192 723
##
## $CCIGT
## 1 2 NA's
## 1099 18578 512
##
## $CCIGAR
## 1 2 NA's
## 1061 18601 527
##
## $CSLT
## 1 2 NA's
## 623 18812 754
##
## $CELCIGT
## 1 2 NA's
## 2703 17066 420
##
## $CHOOKAH
## 1 2 NA's
## 564 18992 633
##
## $CROLLCIGTS
## 1 2 NA's
## 433 19026 730
##
## $CPIPE
## 1 2 NA's
## 175 19284 730
##
## $CSNUS
## 1 2 NA's
## 332 19127 730
##
## $CDISSOLV
## 1 2 NA's
## 112 19347 730
##
## $CBIDIS
## 1 2 NA's
## 108 19351 730
##
## $brand_ecig
## NA's
## 20189
nyts_data[["nyts2018"]] <- nyts_data[["nyts2018"]] %>%
mutate_all(~ replace(., . %in% c("*", "**"), NA)) %>%
mutate(Age=as.character(Age),
Grade=as.character(Grade)
) %>%
mutate(Age=recode(Age,
`19` = ">18",
),
female=recode(female,
`1`= FALSE,
`2` = TRUE,
.default = NA,
.missing = NA),
Grade=recode(Grade,
`13` = "Ungraded/Other"),
Not_HL=recode(Not_HL,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)) %>%
mutate_at(vars(starts_with("HL", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("Race", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("E", ignore.case = FALSE),
starts_with("C", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
`2` = FALSE,
.missing = NA))) %>%
mutate_at(vars(menthol:no_use),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)))
sapply(nyts_data[["nyts2018"]], function(x)
summary(
factor(x)
)
)## $psu
## 015659 057544 058063 058279 058342 086286 086582 086634 086775 086958 086993
## 131 83 241 231 177 223 54 288 250 84 216
## 087009 087143 087205 087214 087537 088258 088304 143354 144110 172268 172362
## 238 133 222 187 183 270 72 372 307 214 249
## 172827 173483 173518 173614 187069 187695 188339 188792 188841 190174 243742
## 192 368 373 155 252 15 383 156 382 368 344
## 243772 244646 245531 245863 246106 258141 259259 259407 273856 303189 314614
## 171 148 320 300 116 84 86 148 61 274 264
## 315356 315841 316022 344472 357756 371868 372907 373105 374569 387227 388116
## 301 317 364 319 166 59 195 317 166 322 25
## 415354 415942 457785 458247 472607 486733 487266 500919 514921 516648 529004
## 134 64 213 182 103 78 166 83 64 165 284
## 529849 559574 559658 572256 600729 601533 601983 602020 603179 629054 644674
## 352 312 197 417 290 406 374 45 71 161 328
## 672288 673839 674805 686156 687050 687585 687958 688552 689044 689416 689634
## 274 277 320 119 126 90 144 303 264 86 305
## 690574 692282 700978 701250 736480 757540 759020
## 182 253 125 15 394 235 252
##
## $finwgt
## 4990.707825052 372.106445056 374.223712424 438.895059192 512.773737505
## 73 54 53 53 50
## 4990.707824997 354.403367156 459.264157663 794.117545838 4990.707825184
## 46 38 38 35 35
## 261.594994077 604.212351194 464.262746508 526.352614715 243.614971982
## 34 34 33 31 30
## 716.756339454 1133.236763357 1063.013428506 499.309679476 725.642399133
## 30 30 29 28 28
## 955.117892997 533.302805442 878.385000967 884.736590151 615.101958781
## 28 27 27 27 26
## 656.112273243 763.304212486 772.024461398 804.949783275 436.289029717
## 26 26 26 26 25
## 1075.075363375 1116.00695267 1120.843771262 1208.191548298 1364.127973987
## 25 25 25 25 25
## 3176.705125185 359.909264221 501.302998165 639.387801493 672.915273738
## 25 24 24 24 24
## 750.014182644 768.617690322 772.265673267 872.656690614 925.421592037
## 24 24 24 24 24
## 925.454369278 934.553252225 997.238713858 1060.007709052 1921.985860852
## 24 24 24 24 24
## 4989.824123193 230.825021393 592.209826559 637.612536618 1173.734572865
## 24 23 23 23 23
## 1215.661901874 1397.810883406 1455.757503148 2086.599584044 4943.253945798
## 23 23 23 23 23
## 4965.403983968 358.261960805 610.908165514 643.867829284 662.274116541
## 23 22 22 22 22
## 755.668600945 792.397022445 890.114756698 1000.670065114 1121.902399257
## 22 22 22 22 22
## 1216.404436426 1484.57374707 1918.7838166 2132.519656006 285.715212581
## 22 22 22 22 21
## 435.458751085 488.084421785 502.351127283 546.319362206 601.212956081
## 21 21 21 21 21
## 635.885463139 662.109306082 753.224172586 757.829169717 809.249572869
## 21 21 21 21 21
## 847.008048039 966.525436209 1007.915531153 1060.586057955 1100.972041909
## 21 21 21 21 21
## 1167.285951387 1271.451496438 104.948041269 303.014353117 306.179881848
## 21 21 20 20 20
## 400.963911867 516.160638629 669.231249605 691.04417579 (Other)
## 20 20 20 20 17599
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 2346 1575 1170 621 1849 1114 548 742 2392 862 774 559 1731 1430 1160 1316
##
## $Age
## >18 10 11 12 13 14 15 16 17 18 9 NA's
## 162 6 1007 2875 3013 2930 2881 2789 2719 1630 58 119
##
## $female
## FALSE TRUE NA's
## 10069 9920 200
##
## $Grade
## 10 11 12 6 7
## 2664 2824 2568 2903 3140
## 8 9 Ungraded/Other NA's
## 3012 2935 16 127
##
## $Not_HL
## FALSE TRUE
## 6423 13766
##
## $HL_Mex
## FALSE TRUE
## 17124 3065
##
## $HL_PR
## FALSE TRUE
## 19532 657
##
## $HL_Cub
## FALSE TRUE
## 19844 345
##
## $HL_Other
## FALSE TRUE
## 18087 2102
##
## $Race_AIAN
## FALSE TRUE
## 18597 1592
##
## $Race_Asian
## FALSE TRUE
## 18970 1219
##
## $Race_BAA
## FALSE TRUE
## 16353 3836
##
## $Race_NHOPI
## FALSE TRUE
## 19612 577
##
## $Race_White
## FALSE TRUE
## 7565 12624
##
## $menthol
## FALSE TRUE
## 18938 1251
##
## $clove_spice
## FALSE TRUE
## 20085 104
##
## $fruit
## FALSE TRUE
## 18400 1789
##
## $chocolate
## FALSE TRUE
## 19940 249
##
## $alcoholic_drink
## FALSE TRUE
## 19825 364
##
## $candy_dessert_sweets
## FALSE TRUE
## 19051 1138
##
## $other
## FALSE TRUE
## 19434 755
##
## $no_use
## FALSE TRUE
## 3584 16605
##
## $ECIGT
## FALSE TRUE NA's
## 16268 3559 362
##
## $ECIGAR
## FALSE TRUE NA's
## 16831 2876 482
##
## $ESLT
## FALSE TRUE NA's
## 18194 1444 551
##
## $EELCIGT
## FALSE TRUE NA's
## 14572 5071 546
##
## $EHOOKAH
## FALSE TRUE NA's
## 18239 1433 517
##
## $EROLLCIGTS
## FALSE TRUE NA's
## 18513 953 723
##
## $EPIPE
## FALSE TRUE NA's
## 19015 451 723
##
## $ESNUS
## FALSE TRUE NA's
## 18629 837 723
##
## $EDISSOLV
## FALSE TRUE NA's
## 19188 278 723
##
## $EBIDIS
## FALSE TRUE NA's
## 19192 274 723
##
## $CCIGT
## FALSE TRUE NA's
## 18578 1099 512
##
## $CCIGAR
## FALSE TRUE NA's
## 18601 1061 527
##
## $CSLT
## FALSE TRUE NA's
## 18812 623 754
##
## $CELCIGT
## FALSE TRUE NA's
## 17066 2703 420
##
## $CHOOKAH
## FALSE TRUE NA's
## 18992 564 633
##
## $CROLLCIGTS
## FALSE TRUE NA's
## 19026 433 730
##
## $CPIPE
## FALSE TRUE NA's
## 19284 175 730
##
## $CSNUS
## FALSE TRUE NA's
## 19127 332 730
##
## $CDISSOLV
## FALSE TRUE NA's
## 19347 112 730
##
## $CBIDIS
## FALSE TRUE NA's
## 19351 108 730
##
## $brand_ecig
## NA's
## 20189
nyts_data[["nyts2019"]] <- nyts_data[["nyts2019"]] %>%
dplyr::select(psu,
finwgt,
stratum,
Q1, #Age
Q2, #Sex
Q3, #Grade
starts_with("Q4"), #Hispanic/Latino
starts_with("Q5"), #Race
starts_with("E",
ignore.case = FALSE),
starts_with("C",
ignore.case = FALSE),
-EHTP,
-CHTP,
Q40, #Brang, e-cigarettes
Q62A, #Menthol # What flavors of tobacco products have you used in the past 30 days? (Select one or more)
Q62B, #Clove or spice
Q62C, #Fruit
Q62D, #Chocolate
Q62E, #Alcoholic Drink
Q62F, #Candy/Desserts/Other Sweets
Q62G, #Some Other Flavor Not Listed Here
) %>%
rename(brand_ecig=Q40,
Age=Q1,
female=Q2,
Grade=Q3,
Not_HL=Q4A,
HL_Mex=Q4B,
HL_PR=Q4C,
HL_Cub=Q4D,
HL_Other=Q4E,
Race_AIAN=Q5A,
Race_Asian=Q5B,
Race_BAA=Q5C,
Race_NHOPI=Q5D,
Race_White=Q5E,
female=Q2,
menthol=Q62A,
clove_spice=Q62B,
fruit=Q62C,
chocolate=Q62D,
alcoholic_drink=Q62E,
candy_dessert_sweets=Q62F,
other=Q62G) %>%
mutate(Age = as.numeric(Age) + 8,
Grade = as.numeric(Grade) + 5,
no_use="missing") %>%
dplyr::select(-starts_with("Q"))## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## Warning in mask$eval_all_mutate(dots[[i]]): NAs introduced by coercion
## $psu
## 58123 73728 73914 86357 86380 86698 86869 86877 86997 87107 87479
## 291 167 171 205 262 94 178 346 220 71 222
## 87601 87669 87860 87876 88243 171990 172758 173174 173515 173535 173649
## 184 198 240 187 162 271 305 68 337 186 204
## 186909 187981 229278 243490 243700 244840 258416 259834 274204 287241 300785
## 133 345 380 480 114 160 146 134 264 134 316
## 300814 303802 316013 358608 373709 374512 374814 386930 387529 401006 401530
## 331 249 367 41 433 191 268 422 362 279 170
## 415984 416340 416550 417008 445315 486486 487128 487177 487457 487518 501192
## 282 92 133 218 247 286 305 312 91 167 189
## 514427 515669 516003 516819 516849 529165 529557 530666 531454 543901 559013
## 125 84 268 145 227 219 104 140 267 304 267
## 559459 586535 601420 601577 601913 602241 602677 674314 686520 688517 688727
## 313 150 286 328 24 384 112 126 165 51 136
## 688871 689471 689962 690649 690720 693247 701384 729538 729920 732232 757899
## 137 199 147 236 146 117 203 138 100 164 298
## 758808 758911 800237
## 146 92 60
##
## $finwgt
## 298.94381695 1349.5698631 546.11348506 691.07608343 5285.5332095 456.58921394
## 35 34 33 33 33 30
## 1814.6246166 676.96068381 745.55326355 876.04021216 1592.6392583 1162.7807537
## 30 29 29 29 29 28
## 188.96218054 436.15905944 878.15523472 1110.4917206 305.78828093 316.2159641
## 27 27 27 27 26 26
## 511.1744348 646.15466161 690.19319279 1154.5213819 1159.6037522 1405.2169869
## 26 26 26 26 26 26
## 674.64725539 825.52309574 884.6807423 925.71486779 1164.6450091 1362.316235
## 25 25 25 25 25 25
## 558.25390758 625.53648288 839.6866944 882.78302229 886.20209942 1338.2350647
## 24 24 24 24 24 24
## 1772.9717327 225.52526803 792.71025137 911.95033723 956.70266731 353.79114524
## 24 23 23 23 23 22
## 507.50355235 739.96695295 775.05061994 887.67803637 1111.0008494 1194.6677527
## 22 22 22 22 22 22
## 1278.4328612 1363.8639539 1642.2200913 11.150042919 16.065197906 172.15949442
## 22 22 22 21 21 21
## 414.949031 710.93532098 780.25920379 1023.8115393 1203.6836641 1444.3893222
## 21 21 21 21 21 21
## 4411.7913281 178.47168745 566.73417786 631.63868903 670.49736758 728.77064723
## 21 20 20 20 20 20
## 741.08110309 765.27178212 790.13593556 864.21130384 876.30041914 934.24093605
## 20 20 20 20 20 20
## 1114.3023069 1179.018274 1232.8285309 1260.744969 1601.8637426 1756.8757857
## 20 20 20 20 20 20
## 5183.3811612 5268.5549579 78.116704202 436.74312217 679.42299971 940.82420216
## 20 20 19 19 19 19
## 963.51307711 1210.2995777 1366.7316106 1369.8132126 1403.0995315 1453.5670628
## 19 19 19 19 19 19
## 1952.421273 350.36503801 512.19207166 557.49460422 623.97616918 653.51170585
## 19 18 18 18 18 18
## 697.41131479 751.91370328 799.96587077 (Other)
## 18 18 18 16757
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 2024 716 843 226 2664 1202 268 369 2958 714 665 688 2553 1001 917 1210
##
## $Age
## 9 10 11 12 13 14 15 16 17 18 19 NA's
## 35 19 1108 2789 3078 2810 2593 2523 2527 1376 122 38
##
## $female
## .N 1 2
## 116 9803 9099
##
## $Grade
## 6 7 8 9 10 11 12 13 NA's
## 2944 3024 2869 2790 2499 2502 2306 27 57
##
## $Not_HL
## .N .Z 1 NA's
## 334 2 13118 5564
##
## $HL_Mex
## .N .Z 1 NA's
## 334 2 3060 15622
##
## $HL_PR
## .N .Z 1 NA's
## 334 2 536 18146
##
## $HL_Cub
## .N .Z 1 NA's
## 334 2 213 18469
##
## $HL_Other
## .N .Z 1 NA's
## 334 2 2141 16541
##
## $brand_ecig
## .N .S .Z 1 2 3 4 5 6 7 8
## 60 15340 14 528 111 2028 36 32 44 100 725
##
## $Race_AIAN
## .N .Z 1 NA's
## 1161 2 1536 16319
##
## $Race_Asian
## .N .Z 1 NA's
## 1161 2 1443 16412
##
## $Race_BAA
## .N .Z 1 NA's
## 1161 2 3675 14180
##
## $Race_NHOPI
## .N .Z 1 NA's
## 1161 2 666 17189
##
## $Race_White
## .N .Z 1 NA's
## 1161 2 12291 5564
##
## $ECIGT
## 1 2 M
## 2931 16061 26
##
## $ECIGAR
## 1 2 M
## 2541 16441 36
##
## $ESLT
## 1 2 M
## 1270 17704 44
##
## $EELCIGT
## 1 2 M
## 6409 12563 46
##
## $EHOOKAH
## 1 2 M
## 1289 17675 54
##
## $EROLLCIGTS
## 1 2 M
## 832 18005 181
##
## $EPIPE
## 1 2 M
## 489 18336 193
##
## $ESNUS
## 1 2 M
## 616 18209 193
##
## $EDISSOLV
## 1 2 M
## 244 18583 191
##
## $EBIDIS
## 1 2 M
## 221 18605 192
##
## $CCIGT
## 1 2 M
## 748 18227 43
##
## $CCIGAR
## 1 2 M
## 930 18028 60
##
## $CSLT
## 1 2 M
## 531 18441 46
##
## $CELCIGT
## 1 2 M
## 3628 15286 104
##
## $CHOOKAH
## 1 2 M
## 477 18471 70
##
## $CROLLCIGTS
## 1 2 M
## 325 18508 185
##
## $CPIPE
## 1 2 M
## 138 18683 197
##
## $CSNUS
## 1 2 M
## 205 18624 189
##
## $CDISSOLV
## 1 2 M
## 74 18758 186
##
## $CBIDIS
## 1 2 M
## 71 18773 174
##
## $menthol
## .N .S .Z 1 NA's
## 79 15910 22 1617 1390
##
## $clove_spice
## .N .S .Z 1 NA's
## 79 15910 22 88 2919
##
## $fruit
## .N .S .Z 1 NA's
## 79 15910 22 1887 1120
##
## $chocolate
## .N .S .Z 1 NA's
## 79 15910 22 197 2810
##
## $alcoholic_drink
## .N .S .Z 1 NA's
## 79 15910 22 249 2758
##
## $candy_dessert_sweets
## .N .S .Z 1 NA's
## 79 15910 22 1108 1899
##
## $other
## .N .S .Z 1 NA's
## 79 15910 22 385 2622
##
## $no_use
## missing
## 19018
nyts_data[["nyts2019"]] <- nyts_data[["nyts2019"]] %>%
mutate_all(~ replace(., . %in% c(".N",".S",".Z"), NA)) %>%
mutate(Age=as.character(Age),
Grade=as.character(Grade)
) %>%
mutate(psu=as.character(psu),
Age=recode(Age,
`19` = ">18",
),
female=recode(female,
`1`= FALSE,
`2` = TRUE,
.default = NA),
Grade=recode(Grade,
`13` = "Ungraded/Other"),
Not_HL=recode(Not_HL,
`1` = TRUE,
.default = FALSE,
.missing = FALSE)) %>%
mutate_at(vars(starts_with("HL", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("Race", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing = FALSE))) %>%
mutate_at(vars(starts_with("E", ignore.case = FALSE),
starts_with("C", ignore.case = FALSE)),
list(~recode(.,
`1` = TRUE,
`2` = FALSE,
.default = NA))) %>%
mutate(brand_ecig = recode(brand_ecig,
`1` = "Other", #levels 1,8 combined to `Other`
`2` = "Blu",
`3` = "JUUL",
`4` = "Logic",
`5` = "MarkTen",
`6` = "NJOY",
`7` = "Vuse",
`8` = "Other")) %>%
mutate_at(vars(menthol:no_use),
list(~recode(.,
`1` = TRUE,
.default = FALSE,
.missing =FALSE))) #Ask Michael about this if unclear
sapply(nyts_data[["nyts2019"]], function(x)
summary(
factor(x)
)
)## $psu
## 171990 172758 173174 173515 173535 173649 186909 187981 229278 243490 243700
## 271 305 68 337 186 204 133 345 380 480 114
## 244840 258416 259834 274204 287241 300785 300814 303802 316013 358608 373709
## 160 146 134 264 134 316 331 249 367 41 433
## 374512 374814 386930 387529 401006 401530 415984 416340 416550 417008 445315
## 191 268 422 362 279 170 282 92 133 218 247
## 486486 487128 487177 487457 487518 501192 514427 515669 516003 516819 516849
## 286 305 312 91 167 189 125 84 268 145 227
## 529165 529557 530666 531454 543901 559013 559459 58123 586535 601420 601577
## 219 104 140 267 304 267 313 291 150 286 328
## 601913 602241 602677 674314 686520 688517 688727 688871 689471 689962 690649
## 24 384 112 126 165 51 136 137 199 147 236
## 690720 693247 701384 729538 729920 732232 73728 73914 757899 758808 758911
## 146 117 203 138 100 164 167 171 298 146 92
## 800237 86357 86380 86698 86869 86877 86997 87107 87479 87601 87669
## 60 205 262 94 178 346 220 71 222 184 198
## 87860 87876 88243
## 240 187 162
##
## $finwgt
## 298.94381695 1349.5698631 546.11348506 691.07608343 5285.5332095 456.58921394
## 35 34 33 33 33 30
## 1814.6246166 676.96068381 745.55326355 876.04021216 1592.6392583 1162.7807537
## 30 29 29 29 29 28
## 188.96218054 436.15905944 878.15523472 1110.4917206 305.78828093 316.2159641
## 27 27 27 27 26 26
## 511.1744348 646.15466161 690.19319279 1154.5213819 1159.6037522 1405.2169869
## 26 26 26 26 26 26
## 674.64725539 825.52309574 884.6807423 925.71486779 1164.6450091 1362.316235
## 25 25 25 25 25 25
## 558.25390758 625.53648288 839.6866944 882.78302229 886.20209942 1338.2350647
## 24 24 24 24 24 24
## 1772.9717327 225.52526803 792.71025137 911.95033723 956.70266731 353.79114524
## 24 23 23 23 23 22
## 507.50355235 739.96695295 775.05061994 887.67803637 1111.0008494 1194.6677527
## 22 22 22 22 22 22
## 1278.4328612 1363.8639539 1642.2200913 11.150042919 16.065197906 172.15949442
## 22 22 22 21 21 21
## 414.949031 710.93532098 780.25920379 1023.8115393 1203.6836641 1444.3893222
## 21 21 21 21 21 21
## 4411.7913281 178.47168745 566.73417786 631.63868903 670.49736758 728.77064723
## 21 20 20 20 20 20
## 741.08110309 765.27178212 790.13593556 864.21130384 876.30041914 934.24093605
## 20 20 20 20 20 20
## 1114.3023069 1179.018274 1232.8285309 1260.744969 1601.8637426 1756.8757857
## 20 20 20 20 20 20
## 5183.3811612 5268.5549579 78.116704202 436.74312217 679.42299971 940.82420216
## 20 20 19 19 19 19
## 963.51307711 1210.2995777 1366.7316106 1369.8132126 1403.0995315 1453.5670628
## 19 19 19 19 19 19
## 1952.421273 350.36503801 512.19207166 557.49460422 623.97616918 653.51170585
## 19 18 18 18 18 18
## 697.41131479 751.91370328 799.96587077 (Other)
## 18 18 18 16757
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1 HU2 HU3 HU4
## 2024 716 843 226 2664 1202 268 369 2958 714 665 688 2553 1001 917 1210
##
## $Age
## >18 10 11 12 13 14 15 16 17 18 9 NA's
## 122 19 1108 2789 3078 2810 2593 2523 2527 1376 35 38
##
## $female
## FALSE TRUE NA's
## 9803 9099 116
##
## $Grade
## 10 11 12 6 7
## 2499 2502 2306 2944 3024
## 8 9 Ungraded/Other NA's
## 2869 2790 27 57
##
## $Not_HL
## FALSE TRUE
## 5900 13118
##
## $HL_Mex
## FALSE TRUE
## 15958 3060
##
## $HL_PR
## FALSE TRUE
## 18482 536
##
## $HL_Cub
## FALSE TRUE
## 18805 213
##
## $HL_Other
## FALSE TRUE
## 16877 2141
##
## $brand_ecig
## Blu JUUL Logic MarkTen NJOY Other Vuse NA's
## 111 2028 36 32 44 1253 100 15414
##
## $Race_AIAN
## FALSE TRUE
## 17482 1536
##
## $Race_Asian
## FALSE TRUE
## 17575 1443
##
## $Race_BAA
## FALSE TRUE
## 15343 3675
##
## $Race_NHOPI
## FALSE TRUE
## 18352 666
##
## $Race_White
## FALSE TRUE
## 6727 12291
##
## $ECIGT
## FALSE TRUE NA's
## 16061 2931 26
##
## $ECIGAR
## FALSE TRUE NA's
## 16441 2541 36
##
## $ESLT
## FALSE TRUE NA's
## 17704 1270 44
##
## $EELCIGT
## FALSE TRUE NA's
## 12563 6409 46
##
## $EHOOKAH
## FALSE TRUE NA's
## 17675 1289 54
##
## $EROLLCIGTS
## FALSE TRUE NA's
## 18005 832 181
##
## $EPIPE
## FALSE TRUE NA's
## 18336 489 193
##
## $ESNUS
## FALSE TRUE NA's
## 18209 616 193
##
## $EDISSOLV
## FALSE TRUE NA's
## 18583 244 191
##
## $EBIDIS
## FALSE TRUE NA's
## 18605 221 192
##
## $CCIGT
## FALSE TRUE NA's
## 18227 748 43
##
## $CCIGAR
## FALSE TRUE NA's
## 18028 930 60
##
## $CSLT
## FALSE TRUE NA's
## 18441 531 46
##
## $CELCIGT
## FALSE TRUE NA's
## 15286 3628 104
##
## $CHOOKAH
## FALSE TRUE NA's
## 18471 477 70
##
## $CROLLCIGTS
## FALSE TRUE NA's
## 18508 325 185
##
## $CPIPE
## FALSE TRUE NA's
## 18683 138 197
##
## $CSNUS
## FALSE TRUE NA's
## 18624 205 189
##
## $CDISSOLV
## FALSE TRUE NA's
## 18758 74 186
##
## $CBIDIS
## FALSE TRUE NA's
## 18773 71 174
##
## $menthol
## FALSE TRUE
## 17401 1617
##
## $clove_spice
## FALSE TRUE
## 18930 88
##
## $fruit
## FALSE TRUE
## 17131 1887
##
## $chocolate
## FALSE TRUE
## 18821 197
##
## $alcoholic_drink
## FALSE TRUE
## 18769 249
##
## $candy_dessert_sweets
## FALSE TRUE
## 17910 1108
##
## $other
## FALSE TRUE
## 18633 385
##
## $no_use
## FALSE
## 19018
nyts_data <- nyts_data %>%
map_df(bind_rows, .id = "year") %>%
mutate(year=as.numeric(str_remove(year,"nyts")))
sapply(nyts_data, class)## year psu finwgt
## "numeric" "character" "numeric"
## stratum Age female
## "character" "character" "logical"
## Grade Not_HL HL_Mex
## "character" "logical" "logical"
## HL_PR HL_Cub HL_Other
## "logical" "logical" "logical"
## Race_AIAN Race_Asian Race_BAA
## "logical" "logical" "logical"
## Race_NHOPI Race_White ECIGT
## "logical" "logical" "logical"
## ECIGAR ESLT EELCIGT
## "logical" "logical" "logical"
## EROLLCIGTS EBIDIS EHOOKAH
## "logical" "logical" "logical"
## EPIPE ESNUS EDISSOLV
## "logical" "logical" "logical"
## CCIGT CCIGAR CSLT
## "logical" "logical" "logical"
## CELCIGT CROLLCIGTS CBIDIS
## "logical" "logical" "logical"
## CHOOKAH CPIPE CSNUS
## "logical" "logical" "logical"
## CDISSOLV brand_ecig menthol
## "logical" "character" "logical"
## clove_spice fruit chocolate
## "logical" "logical" "logical"
## alcoholic_drink candy_dessert_sweets other
## "logical" "logical" "logical"
## no_use
## "logical"
## $year
## 2015 2016 2017 2018 2019
## 17711 20675 17872 20189 19018
##
## $psu
## 187822 600815 373302 243490 086878 087664 173584 373427 458137 515814
## 565 531 501 480 479 470 469 463 452 450
## 087896 687909 374028 373709 386930 087843 188307 692424 572256 731503
## 437 436 435 433 422 421 421 421 417 414
## 601533 372861 087656 343702 736480 602241 188339 188841 229278 187681
## 406 401 397 394 394 384 383 382 380 379
## 530582 601983 173518 758261 758520 143354 416045 314736 188489 173483
## 379 374 373 373 373 372 371 370 369 368
## 190174 689327 316013 372465 316022 515990 087614 387529 014595 644656
## 368 368 367 367 364 364 363 362 354 354
## 529849 258711 344194 086754 86877 187981 245271 243742 514830 186117
## 352 350 348 347 346 345 345 344 344 341
## 173515 087425 300946 374456 529391 172374 300814 559658 572477 601577
## 337 336 336 336 333 331 331 331 328 328
## 644674 058470 314939 173458 387227 188207 245531 486665 674805 344472
## 328 325 323 322 322 320 320 320 320 319
## 087568 174258 486124 315841 373105 300785 074170 087174 015438 559459
## 318 318 318 317 317 316 314 314 313 313
## 730385 487177 559574 302266 400915 560847 087003 673286 144110 (Other)
## 313 312 312 309 309 309 308 308 307 59142
##
## $finwgt
## 6084.762382383 4990.707825052 6084.749363267 372.106445056 374.223712424
## 90 73 61 54 53
## 438.895059192 871.325553937 388.086140156 512.773737505 6084.748763328
## 53 52 51 50 50
## 471.940845283 390.583989416 393.890426751 405.380567077 641.647375466
## 49 48 48 48 48
## 472.183232467 1462.436434424 4990.707824997 593.037596627 895.030720016
## 47 47 46 45 44
## 1294.137423906 1438.420759833 480.328096721 354.403367156 459.264157663
## 44 44 39 38 38
## 342.509547149 934.989137039 1836.652739308 460.564361052 702.57430816
## 37 37 37 36 36
## 298.94381695 645.096986799 688.756981919 724.56606859 794.117545838
## 35 35 35 35 35
## 1784.368053098 4990.707825184 261.594994077 376.209171932 604.212351194
## 35 35 34 34 34
## 1349.5698631 6084.747889789 464.262746508 518.253252285 546.11348506
## 34 34 33 33 33
## 577.454052555 651.46204257 691.07608343 929.843069043 967.677487198
## 33 33 33 33 33
## 5285.5332095 452.180288822 541.333365673 729.816382606 787.40156861
## 33 32 32 32 32
## 835.705455892 888.382540193 927.94099198 321.964869964 348.981595173
## 32 32 32 31 31
## 473.352544161 526.352614715 688.65484377 851.768379729 868.130099018
## 31 31 31 31 31
## 894.645660874 903.144043691 984.845596021 1058.307376853 6505.08401827
## 31 31 31 31 31
## 243.614971982 456.58921394 550.786275093 565.667360783 666.989424614
## 30 30 30 30 30
## 701.063606043 716.756339454 759.980607023 793.263666402 855.933815842
## 30 30 30 30 30
## 1133.236763357 1814.6246166 376.294559675 409.581862696 480.026932681
## 30 30 29 29 29
## 543.10044387 655.970957179 676.96068381 745.55326355 801.149846011
## 29 29 29 29 29
## 848.614920471 876.04021216 926.022139243 946.819967478 1015.462088582
## 29 29 29 29 29
## 1016.149108108 1019.981866234 1040.468408082 1063.013428506 (Other)
## 29 29 29 29 91861
##
## $stratum
## BR1 BR2 BR3 BR4 BU1 BU2 BU3 BU4 HR1 HR2 HR3 HR4 HU1
## 10080 5864 4798 2886 9212 4851 3221 2741 13570 2932 3025 2189 9732
## HU2 HU3 HU4
## 7945 5548 6871
##
## $Age
## >18 10 11 12 13 14 15 16 17 18 9 NA's
## 727 50 5360 13499 14613 14036 13498 13205 12754 7108 198 417
##
## $female
## FALSE TRUE NA's
## 48149 46538 778
##
## $Grade
## 10 11 12 6 7
## 13118 12857 12068 14158 14823
## 8 9 Ungraded/Other NA's
## 14301 13561 102 477
##
## $Not_HL
## FALSE TRUE
## 29372 66093
##
## $HL_Mex
## FALSE TRUE
## 81323 14142
##
## $HL_PR
## FALSE TRUE
## 92477 2988
##
## $HL_Cub
## FALSE TRUE
## 94236 1229
##
## $HL_Other
## FALSE TRUE
## 85451 10014
##
## $Race_AIAN
## FALSE TRUE
## 88247 7218
##
## $Race_Asian
## FALSE TRUE
## 88997 6468
##
## $Race_BAA
## FALSE TRUE
## 75419 20046
##
## $Race_NHOPI
## FALSE TRUE
## 92515 2950
##
## $Race_White
## FALSE TRUE
## 37558 57907
##
## $ECIGT
## FALSE TRUE NA's
## 77584 17176 705
##
## $ECIGAR
## FALSE TRUE NA's
## 80549 13984 932
##
## $ESLT
## FALSE TRUE NA's
## 87950 6562 953
##
## $EELCIGT
## FALSE TRUE NA's
## 70229 24333 903
##
## $EROLLCIGTS
## FALSE TRUE NA's
## 89410 4436 1619
##
## $EBIDIS
## FALSE TRUE NA's
## 92679 1156 1630
##
## $EHOOKAH
## FALSE TRUE NA's
## 85617 8562 1286
##
## $EPIPE
## FALSE TRUE NA's
## 91658 2176 1631
##
## $ESNUS
## FALSE TRUE NA's
## 90689 3145 1631
##
## $EDISSOLV
## FALSE TRUE NA's
## 92733 1103 1629
##
## $CCIGT
## FALSE TRUE NA's
## 89668 4878 919
##
## $CCIGAR
## FALSE TRUE NA's
## 89312 5023 1130
##
## $CSLT
## FALSE TRUE NA's
## 91541 2796 1128
##
## $CELCIGT
## FALSE TRUE NA's
## 83510 11161 794
##
## $CROLLCIGTS
## FALSE TRUE NA's
## 91807 1976 1682
##
## $CBIDIS
## FALSE TRUE NA's
## 93323 471 1671
##
## $CHOOKAH
## FALSE TRUE NA's
## 90853 3142 1470
##
## $CPIPE
## FALSE TRUE NA's
## 92970 801 1694
##
## $CSNUS
## FALSE TRUE NA's
## 92565 1214 1686
##
## $CDISSOLV
## FALSE TRUE NA's
## 93305 477 1683
##
## $brand_ecig
## Blu JUUL Logic MarkTen NJOY Other Vuse NA's
## 111 2028 36 32 44 1253 100 91861
##
## $menthol
## FALSE TRUE NA's
## 73305 4449 17711
##
## $clove_spice
## FALSE TRUE NA's
## 77360 394 17711
##
## $fruit
## FALSE TRUE NA's
## 71945 5809 17711
##
## $chocolate
## FALSE TRUE NA's
## 76875 879 17711
##
## $alcoholic_drink
## FALSE TRUE NA's
## 76510 1244 17711
##
## $candy_dessert_sweets
## FALSE TRUE NA's
## 74188 3566 17711
##
## $other
## FALSE TRUE NA's
## 75675 2079 17711
##
## $no_use
## FALSE TRUE NA's
## 27851 49903 17711
Reminder: Current users are a subset of ever users.
plot1 <- nyts_data %>%
mutate(tobacco_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
apply(1, sum, na.rm=TRUE),
tobacco_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(tobacco_ever = case_when(tobacco_sum_ever > 0 ~ TRUE,
tobacco_sum_ever ==0 ~ FALSE),
tobacco_current = case_when(tobacco_sum_current > 0 ~ TRUE,
tobacco_sum_current ==0 ~ FALSE)) %>%
group_by(year) %>%
summarise(tobacco_ever_year=(sum(tobacco_ever, na.rm = TRUE)*100)/
sum(!is.na(tobacco_ever)),
tobacco_current_year=(sum(tobacco_current, na.rm = TRUE)*100)/
sum(!is.na(tobacco_current))) %>%
rename("Ever"=tobacco_ever_year,
"Current"=tobacco_current_year) %>%
gather(key=User,
value=`Percentage of students`,
-year) %>%
ggplot(aes(x=year,y=`Percentage of students`, linetype=User)) +
geom_line() +
geom_point(show.legend = FALSE) +
scale_linetype_manual(values = c(2,1)) +
scale_y_continuous(breaks = seq(0,70,by=10),
labels = seq(0,70,by=10),
limits = c(0,70)) +
theme_minimal() +
theme(legend.position = "bottom",
axis.title.x = element_blank()) +
labs(title = "How does nicotine use vary over the years?",
subtitle = "Current and ever users of nicotine products",
y = "% of students")## `summarise()` ungrouping output (override with `.groups` argument)
plot2 <- nyts_data %>%
group_by(year,
female) %>%
summarise(EELCIGT_year=(sum(EELCIGT, na.rm = TRUE)*100)/
sum(!is.na(EELCIGT)),
CELCIGT_year=(sum(CELCIGT, na.rm = TRUE)*100)/
sum(!is.na(CELCIGT))) %>%
filter(!is.na(female)) %>%
rename("E-cigarettes, Ever"=EELCIGT_year,
"E-cigarettes, Current"=CELCIGT_year) %>%
gather(key=Category,
value=`Percentage of students`,
-year,
-female) %>%
mutate(User = case_when(Category == "E-cigarettes, Ever" ~ "Ever",
Category == "E-cigarettes, Current" ~ "Current")) %>%
mutate(Sex = case_when(female == TRUE ~ "Females",
female == FALSE ~ "Males")) %>%
ggplot(aes(x=year,y=`Percentage of students`, color=Sex, linetype=User)) +
geom_line() +
geom_point(show.legend = FALSE) +
scale_linetype_manual(values = c(2,1)) +
theme_minimal() +
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 90),
axis.title.x = element_blank()) +
labs(title = "How do vaping rates compare between males and females?",
subtitle = "Current and ever users by gender",
y = "% of students")## `summarise()` regrouping output by 'year' (override with `.groups` argument)
What vaping brands and flavors appear to be used the most frequently?
Huang J, Duan Z, Kwok J, et al. Tob Control 2019;28:146–151.
plot3 <- nyts_data %>%
filter(year==2019) %>%
group_by(brand_ecig) %>%
filter(!is.na(brand_ecig)) %>%
summarise(n = n()) %>%
mutate(total = sum(n),
Percent = n*100/total) %>%
mutate(brand_ecig = fct_reorder(brand_ecig, desc(Percent))) %>%
ggplot(aes(x=brand_ecig,y=Percent, fill=brand_ecig)) +
geom_bar(stat="identity") +
theme_minimal() +
theme(legend.position = "none",
axis.text.x = element_text(size=10),
axis.title.x = element_blank()) +
labs(title = "What vaping brands appear to be used the most frequently?",
subtitle = "Brand of e-cigarette most frequently used in the last 30 days (2019)",
y = "% of e-cigarette users responding")## `summarise()` ungrouping output (override with `.groups` argument)
plot4 <- nyts_data %>%
filter(year!=2015) %>%
group_by(year) %>%
summarise(Menthol=(sum(menthol, na.rm = TRUE)*100)/
sum(!is.na(menthol)),
`Clove or Spice`=(sum(clove_spice, na.rm = TRUE)*100)/
sum(!is.na(clove_spice)),
`Fruit`=(sum(fruit, na.rm = TRUE)*100)/
sum(!is.na(fruit)),
`Chocolate`=(sum(chocolate, na.rm = TRUE)*100)/
sum(!is.na(chocolate)),
`Alcoholic Drink`=(sum(alcoholic_drink, na.rm = TRUE)*100)/
sum(!is.na(alcoholic_drink)),
`Candy/Desserts/Sweets`=(sum(candy_dessert_sweets, na.rm = TRUE)*100)/sum(!is.na(candy_dessert_sweets))) %>%
gather(key=Flavor,value=`Percentage of students`,-year) %>%
ggplot(aes(x=year, y=`Percentage of students`, color=Flavor)) +
geom_line() +
geom_point(show.legend = FALSE) +
theme_minimal() +
theme(legend.position = "bottom",
axis.text.x = element_text(angle = 90),
axis.title.x = element_blank()) +
labs(title = "What flavors appear to be used the most frequently in nicotine products?",
subtitle = "Flavors of tobacco products used in the past 30 days")## `summarise()` ungrouping output (override with `.groups` argument)
plot5 <- nyts_data %>%
filter(year!=2015) %>%
filter(menthol==TRUE|
clove_spice==TRUE|
fruit==TRUE|
chocolate==TRUE|
alcoholic_drink==TRUE|
candy_dessert_sweets==TRUE|
other==TRUE) %>%
mutate(ecig_sum_ever = select(., EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
ecig_sum_current = select(., CELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
select(.,-EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
select(.,-CELCIGT) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(ecig_ever = case_when(ecig_sum_ever > 0 ~ TRUE,
ecig_sum_ever ==0 ~ FALSE),
ecig_current = case_when(ecig_sum_current > 0 ~ TRUE,
ecig_sum_current ==0 ~ FALSE),
non_ecig_ever = case_when(non_ecig_sum_ever > 0 ~ TRUE,
non_ecig_sum_ever ==0 ~ FALSE),
non_ecig_current = case_when(non_ecig_sum_current > 0 ~ TRUE,
non_ecig_sum_current ==0 ~ FALSE)) %>%
mutate(ecig_only_ever = case_when(ecig_ever == TRUE &
non_ecig_ever ==FALSE ~ TRUE,
TRUE ~ FALSE),
ecig_only_current = case_when(ecig_current == TRUE &
non_ecig_ever ==FALSE ~ TRUE,
TRUE ~ FALSE),
non_ecig_only_ever = case_when(non_ecig_ever == TRUE &
ecig_ever ==FALSE ~ TRUE,
TRUE ~ FALSE),
non_ecig_only_current = case_when(non_ecig_current == TRUE &
ecig_ever ==FALSE ~ TRUE,
TRUE ~ FALSE)) %>%
mutate(Group = case_when(ecig_only_ever==TRUE |
ecig_only_current==TRUE ~ "Only e-cigarettes",
non_ecig_only_ever==TRUE |
non_ecig_only_current==TRUE ~ "Only other products",
TRUE ~ "Both")) %>%
filter(Group!="Both") %>%
group_by(year, Group) %>%
summarise(`Menthol`=(sum(menthol, na.rm = TRUE)*100)/
sum(!is.na(menthol)),
`Clove or Spice`=(sum(clove_spice, na.rm = TRUE)*100)/
sum(!is.na(clove_spice)),
`Fruit`=(sum(fruit, na.rm = TRUE)*100)/sum(!is.na(fruit)),
`Chocolate`=(sum(chocolate, na.rm = TRUE)*100)/
sum(!is.na(chocolate)),
`Alcoholic Drink`=(sum(alcoholic_drink, na.rm = TRUE)*100)/
sum(!is.na(alcoholic_drink)),
`Candy/Desserts/Sweets`=(sum(candy_dessert_sweets, na.rm = TRUE)*100)/
sum(!is.na(candy_dessert_sweets)),
`Other`=(sum(other, na.rm = TRUE)*100)/
sum(!is.na(other)),
Respondents=n()) %>%
gather(key=Flavor,value=`Percentage of students`,-year, -Group, -Respondents) %>%
filter(!is.na(`Percentage of students`),
Flavor!="Other") %>%
group_by(Flavor) %>%
mutate(affirmative=(Respondents * `Percentage of students`)/100) %>%
mutate(flavor_mean = sum(affirmative)/sum(Respondents)) %>%
ungroup() %>%
mutate(flavor_mean_rank = dense_rank(flavor_mean),
Flavor = fct_reorder(Flavor, flavor_mean_rank)) %>%
ggplot(aes(x=year, y=`Percentage of students`, color=Group)) +
facet_wrap(.~Flavor,ncol=3) +
geom_line() +
geom_point(show.legend = FALSE) +
theme_minimal() +
theme(legend.position = "bottom",
axis.title.x = element_blank(),
axis.text.x = element_text(angle = 90)) +
labs(title = "Among users of only one type of product, what vaping flavors appear to be used the most frequently?",
subtitle = "Percent reporting only e-cigarette use vs only other nicotine product use")## `summarise()` regrouping output by 'year' (override with `.groups` argument)
Have vaping rates possibly influenced tobacco/nicotine use?
plot6 <- nyts_data %>%
group_by(year) %>%
summarise(ECIGT_year=(sum(ECIGT, na.rm = TRUE)*100)/
sum(!is.na(ECIGT)),
EELCIGT_year=(sum(EELCIGT, na.rm = TRUE)*100)/
sum(!is.na(EELCIGT)),
CCIGT_year=(sum(CCIGT, na.rm = TRUE)*100)/
sum(!is.na(CCIGT)),
CELCIGT_year=(sum(CELCIGT, na.rm = TRUE)*100)/
sum(!is.na(CELCIGT))) %>%
rename("Cigarettes, Ever"=ECIGT_year,
"E-cigarettes, Ever"=EELCIGT_year,
"Cigarettes, Current"=CCIGT_year,
"E-cigarettes, Current"=CELCIGT_year) %>%
gather(key=Category,
value=`Percentage of students`,
-year) %>%
mutate(User = case_when(Category == "Cigarettes, Ever" ~ "Ever",
Category == "E-cigarettes, Ever" ~ "Ever",
Category == "Cigarettes, Current" ~ "Current",
Category == "E-cigarettes, Current" ~ "Current")) %>%
mutate(Product = case_when(Category == "Cigarettes, Ever" ~ "Cigarettes",
Category == "E-cigarettes, Ever" ~ "E-cigarettes",
Category == "Cigarettes, Current" ~ "Cigarettes",
Category == "E-cigarettes, Current" ~ "E-cigarettes")) %>%
ggplot(aes(x=year,y=`Percentage of students`, color=Product, linetype=User)) +
geom_line() +
geom_point(show.legend = FALSE) +
scale_linetype_manual(values = c(2,1)) +
theme_minimal() +
theme(legend.position = "bottom",
axis.title.x = element_blank()) +
labs(title = "How does e-cigarette use compare to cigarette use?",
subtitle = "Current and ever users of e-cigarettes and cigarettes",
y = "% of students")## `summarise()` ungrouping output (override with `.groups` argument)
plot7 <- nyts_data %>%
mutate(ecig_sum_ever = select(., EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
ecig_sum_current = select(., CELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
select(.,-EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
select(.,-CELCIGT) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(ecig_ever = case_when(ecig_sum_ever > 0 ~ TRUE,
ecig_sum_ever ==0 ~ FALSE),
ecig_current = case_when(ecig_sum_current > 0 ~ TRUE,
ecig_sum_current ==0 ~ FALSE),
non_ecig_ever = case_when(non_ecig_sum_ever > 0 ~ TRUE,
non_ecig_sum_ever ==0 ~ FALSE),
non_ecig_current = case_when(non_ecig_sum_current > 0 ~ TRUE,
non_ecig_sum_current ==0 ~ FALSE)) %>%
group_by(year) %>%
summarise(ecig_ever_year=(sum(ecig_ever, na.rm = TRUE)*100)/
sum(!is.na(ecig_ever)),
ecig_current_year=(sum(ecig_current, na.rm = TRUE)*100)/
sum(!is.na(ecig_current)),
non_ecig_ever_year=(sum(non_ecig_ever, na.rm = TRUE)*100)/
sum(!is.na(non_ecig_ever)),
non_ecig_current_year=(sum(non_ecig_current, na.rm = TRUE)*100)/
sum(!is.na(non_ecig_current))) %>%
gather(key=Category,
value=`Percentage of students`,
-year) %>%
mutate(User = case_when(Category =="ecig_ever_year" ~ "Ever",
Category =="non_ecig_ever_year" ~ "Ever",
Category =="ecig_current_year" ~ "Current",
Category =="non_ecig_current_year" ~ "Current")) %>%
mutate(Product = case_when(Category =="ecig_ever_year" ~ "E-cigarettes",
Category =="non_ecig_ever_year" ~ "Other products",
Category =="ecig_current_year" ~ "E-cigarettes",
Category =="non_ecig_current_year" ~ "Other products")) %>%
filter(User=="Ever") %>%
ggplot(aes(x=year,y=`Percentage of students`, color=Product)) +
geom_line(linetype=1) + # geom_bar(stat="identity", position = "dodge", color="black") +
geom_point(show.legend = FALSE) +
scale_y_continuous(breaks = seq(10, 60, by = 10), limits = c(10,60)) +
theme_minimal() +
theme(legend.position = "bottom",
axis.title.x = element_blank()) +
labs(title = "How does e-cigarette ever use compare to ever use of other products over the years?",
subtitle = "E-cigarette and non-e-cigarette use",
y = "% of students")## `summarise()` ungrouping output (override with `.groups` argument)
plot8 <- nyts_data %>%
mutate(ecig_sum_ever = select(., EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
ecig_sum_current = select(., CELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
select(.,-EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
select(.,-CELCIGT) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(ecig_ever = case_when(ecig_sum_ever > 0 ~ TRUE,
ecig_sum_ever ==0 ~ FALSE),
ecig_current = case_when(ecig_sum_current > 0 ~ TRUE,
ecig_sum_current ==0 ~ FALSE),
non_ecig_ever = case_when(non_ecig_sum_ever > 0 ~ TRUE,
non_ecig_sum_ever ==0 ~ FALSE),
non_ecig_current = case_when(non_ecig_sum_current > 0 ~ TRUE,
non_ecig_sum_current ==0 ~ FALSE)) %>%
group_by(year) %>%
summarise(ecig_ever_year=(sum(ecig_ever, na.rm = TRUE)*100)/
sum(!is.na(ecig_ever)),
ecig_current_year=(sum(ecig_current, na.rm = TRUE)*100)/
sum(!is.na(ecig_current)),
non_ecig_ever_year=(sum(non_ecig_ever, na.rm = TRUE)*100)/
sum(!is.na(non_ecig_ever)),
non_ecig_current_year=(sum(non_ecig_current, na.rm = TRUE)*100)/
sum(!is.na(non_ecig_current))) %>%
gather(key=Category,
value=`Percentage of students`,
-year) %>%
mutate(User = case_when(Category =="ecig_ever_year" ~ "Ever",
Category =="non_ecig_ever_year" ~ "Ever",
Category =="ecig_current_year" ~ "Current",
Category =="non_ecig_current_year" ~ "Current")) %>%
mutate(Product = case_when(Category =="ecig_ever_year" ~ "E-cigarettes",
Category =="non_ecig_ever_year" ~ "Other products",
Category =="ecig_current_year" ~ "E-cigarettes",
Category =="non_ecig_current_year" ~ "Other products")) %>%
ggplot(aes(x=year,y=`Percentage of students`, color=Product, linetype=User)) +
geom_line() +
geom_point(show.legend = FALSE) +
scale_linetype_manual(values = c(2,1)) +
scale_y_continuous(breaks = seq(0, 60, by = 10), limits = c(0,60)) +
theme_minimal() +
theme(legend.position = "bottom",
axis.title.x = element_blank()) +
labs(title = "How does e-cigarette use compare to use of other products over the years?",
subtitle = "E-cigarette and non-e-cigarette use",
y = "% of students")## `summarise()` ungrouping output (override with `.groups` argument)
plotA_uw <- plot1 +
theme(axis.title.x = element_blank(),
legend.position = "none") +
labs(title = "Nicotine product users more prevalent after 2017",
subtitle = NULL,
y = "% of students")
plotB_uw <- plot7 +
theme(axis.title.x = element_blank(),
legend.position = "none") +
labs(title = "% Ever trying e-cigarettes increases &\n% ever trying other products decreases",
subtitle = NULL,
y = "% of students")
plotC_uw <- plot8 +
theme(axis.title.x = element_blank(),
legend.position = "none") +
labs(title = "% Using e-cigarettes increases &\n% using Other products decreases",
subtitle = NULL,
y = "% of students")
title_uw <- ggdraw() +
draw_label(
"Have vaping rates possibly influenced tobacco/nicotine use?",
fontface = 'bold',
size=14,
x = 0,
hjust = 0
) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
plotsA_uw <- plot_grid(plotA_uw,
rel_widths = c(1,1))
plotsBC_uw <- plot_grid(plotB_uw,
plotC_uw,
rel_widths = c(1,1))
legend_uw <- get_legend(plotB_uw +
theme(legend.position = "bottom",
legend.direction = "horizontal"))
figure_uw <- plot_grid(title_uw,
plotsA_uw,
plotsBC_uw,
legend_uw,
ncol = 1,
rel_heights = c(0.1,
1,
1,
0.1),
scale = 1.0)
figure_uwplotA_w <- nyts_data %>%
mutate(tobacco_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
apply(1, sum, na.rm=TRUE),
tobacco_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(tobacco_ever = case_when(tobacco_sum_ever > 0 ~ TRUE,
tobacco_sum_ever ==0 ~ FALSE),
tobacco_current = case_when(tobacco_sum_current > 0 ~ TRUE,
tobacco_sum_current ==0 ~ FALSE)) %>%
as_survey_design(strata = stratum, ids = psu, weight = finwgt, nest=TRUE) %>%
group_by(year) %>%
summarise(tobacco_ever_year = survey_mean(tobacco_ever, vartype = "ci", na.rm=TRUE),
tobacco_current_year = survey_mean(tobacco_current, vartype = "ci", na.rm=TRUE)) %>%
mutate_at(vars(-year), "*", 100) %>%
gather(key=Type,
value=`Percentage of students`,
-year) %>%
mutate(Estimate = case_when(grepl("_low", Type) ~ "Lower",
grepl("_upp", Type) ~ "Upper",
TRUE ~ "Mean"),
User = case_when(grepl("ever", Type) ~ "Ever",
grepl("current", Type) ~ "Current",
TRUE ~ "Mean")) %>%
dplyr::select(-Type) %>%
spread(Estimate, `Percentage of students`) %>%
ggplot(aes(x=year,y=Mean)) +
geom_line(aes(linetype=User)) +
geom_linerange(aes(ymin = Lower, ymax = Upper), show.legend = FALSE) +
scale_linetype_manual(values = c(2,1)) +
scale_y_continuous(breaks = seq(0,70,by=10),
labels = seq(0,70,by=10),
limits = c(0,70)) +
theme_minimal() +
theme(legend.position = "none",
axis.title.x = element_blank()) +
labs(title = "Nicotine product users more prevalent after 2017",
y = "% of students")## Warning: The `add` argument of `group_by()` is deprecated as of dplyr 1.0.0.
## Please use the `.add` argument instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_warnings()` to see where this warning was generated.
plotB_w <- nyts_data %>%
mutate(ecig_sum_ever = select(., EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
ecig_sum_current = select(., CELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
select(.,-EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
select(.,-CELCIGT) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(ecig_ever = case_when(ecig_sum_ever > 0 ~ TRUE,
ecig_sum_ever ==0 ~ FALSE),
ecig_current = case_when(ecig_sum_current > 0 ~ TRUE,
ecig_sum_current ==0 ~ FALSE),
non_ecig_ever = case_when(non_ecig_sum_ever > 0 ~ TRUE,
non_ecig_sum_ever ==0 ~ FALSE),
non_ecig_current = case_when(non_ecig_sum_current > 0 ~ TRUE,
non_ecig_sum_current ==0 ~ FALSE)) %>%
as_survey_design(strata = stratum, ids = psu, weight = finwgt, nest=TRUE) %>%
group_by(year) %>%
summarise(ecig_ever_year = survey_mean(ecig_ever, vartype = "ci", na.rm=TRUE),
ecig_current_year = survey_mean(ecig_current, vartype = "ci", na.rm=TRUE),
non_ecig_ever_year = survey_mean(non_ecig_ever, vartype = "ci", na.rm=TRUE),
non_ecig_current_year = survey_mean(non_ecig_current, vartype = "ci", na.rm=TRUE)) %>%
mutate_at(vars(-year), "*", 100) %>%
dplyr::select(year,
ecig_ever_year,
ecig_current_year,
non_ecig_ever_year,
non_ecig_current_year,
contains("low"),
contains("upp")) %>%
gather(key=Category,
value=`Percentage of students`,
-year) %>%
mutate(Estimate = case_when(grepl("_low", Category) ~ "Lower",
grepl("_upp", Category) ~ "Upper",
TRUE ~ "Mean"),
User = case_when(grepl("current", Category) ~ "Current",
TRUE ~ "Ever",),
Product = case_when(grepl("non_ecig", Category) ~ "Other products",
TRUE ~ "E-cigarettes")) %>%
dplyr::select(-Category) %>%
spread(Estimate, `Percentage of students`) %>%
filter(User=="Ever") %>%
dplyr::rename("Lower_temp" = Upper,
"Upper_temp" = Lower) %>%
dplyr::rename("Lower"=Lower_temp,
"Upper"=Upper_temp) %>%
ggplot(aes(x=year,y=Mean, color=Product)) +
geom_line(linetype=1) +
geom_linerange(aes(ymin = Lower, ymax = Upper), show.legend = FALSE) +
scale_y_continuous(breaks = seq(10, 60, by = 10), limits = c(10,60)) +
theme_minimal() +
theme(legend.position = "none",
axis.title.x = element_blank()) +
labs(title = "% ever trying e-cigarettes increases &\n% ever trying other products decreases",
y = "% of students")
plotC_w <- nyts_data %>%
mutate(ecig_sum_ever = select(., EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
ecig_sum_current = select(., CELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
select(.,-EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
select(.,-CELCIGT) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(ecig_ever = case_when(ecig_sum_ever > 0 ~ TRUE,
ecig_sum_ever ==0 ~ FALSE),
ecig_current = case_when(ecig_sum_current > 0 ~ TRUE,
ecig_sum_current ==0 ~ FALSE),
non_ecig_ever = case_when(non_ecig_sum_ever > 0 ~ TRUE,
non_ecig_sum_ever ==0 ~ FALSE),
non_ecig_current = case_when(non_ecig_sum_current > 0 ~ TRUE,
non_ecig_sum_current ==0 ~ FALSE)) %>%
as_survey_design(strata = stratum, ids = psu, weight = finwgt, nest=TRUE) %>%
group_by(year) %>%
summarise(ecig_ever_year = survey_mean(ecig_ever, vartype = "ci", na.rm=TRUE),
ecig_current_year = survey_mean(ecig_current, vartype = "ci", na.rm=TRUE),
non_ecig_ever_year = survey_mean(non_ecig_ever, vartype = "ci", na.rm=TRUE),
non_ecig_current_year = survey_mean(non_ecig_current, vartype = "ci", na.rm=TRUE)) %>%
mutate_at(vars(-year), "*", 100) %>%
dplyr::select(year,
ecig_ever_year,
ecig_current_year,
non_ecig_ever_year,
non_ecig_current_year,
contains("low"),
contains("upp")) %>%
gather(key=Category,
value=`Percentage of students`,
-year) %>%
mutate(Estimate = case_when(grepl("_low", Category) ~ "Lower",
grepl("_upp", Category) ~ "Upper",
TRUE ~ "Mean"),
User = case_when(grepl("ever", Category) ~ "Ever",
grepl("current", Category) ~ "Current"),
Product = case_when(grepl("non_ecig", Category) ~ "Other products",
TRUE ~ "E-cigarettes")) %>%
dplyr::select(-Category) %>%
spread(Estimate, `Percentage of students`) %>%
ggplot(aes(x=year,y=Mean, color=Product)) +
geom_line(aes(linetype=User)) +
geom_linerange(aes(ymin = Lower, ymax = Upper), show.legend = FALSE) +
scale_linetype_manual(values = c(2,1)) +
scale_y_continuous(breaks = seq(0, 60, by = 10), limits = c(0,60)) +
theme_minimal() +
theme(legend.position = "none",
axis.title.x = element_blank()) +
labs(title = "% Using e-cigarettes increases &\n% using Other products decreases",
y = "% of students")
title_w <- ggdraw() +
draw_label(
expression("Have vaping rates possibly influenced tobacco/nicotine use?"),
fontface = 'bold',
size=14,
x = 0,
hjust = 0
) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
plotsA_w <- plot_grid(plotA_w,
rel_widths = c(1),
align = "v",
axis = "bt")
plotsBC_w <- plot_grid(plotB_w,
plotC_w,
rel_widths = c(1,1),
align = "v",
axis = "bt")
legend_w <- get_legend(plotB_w +
theme(legend.position = "bottom",
legend.direction = "horizontal"))
figure_w <- plot_grid(title_w,
plotsA_w,
plotsBC_w,
legend_w,
ncol = 1,
rel_heights = c(0.1,
1,
1,
0.1),
scale = 1.0)
figure_wplotA_w_8 <- nyts_data %>%
filter((Grade == "8" & year == 2015) |
(Grade == "9" & year == 2016) |
(Grade == "10" & year == 2017) |
(Grade == "11" & year == 2018) |
(Grade == "12" & year == 2019)
) %>%
mutate(tobacco_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
apply(1, sum, na.rm=TRUE),
tobacco_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(tobacco_ever = case_when(tobacco_sum_ever > 0 ~ TRUE,
tobacco_sum_ever ==0 ~ FALSE),
tobacco_current = case_when(tobacco_sum_current > 0 ~ TRUE,
tobacco_sum_current ==0 ~ FALSE)) %>%
as_survey_design(strata = stratum, ids = psu, weight = finwgt) %>%
group_by(year) %>%
summarise(tobacco_ever_year = survey_mean(tobacco_ever, vartype = "ci", na.rm=TRUE),
tobacco_current_year = survey_mean(tobacco_current, vartype = "ci", na.rm=TRUE)) %>%
mutate_at(vars(-year), "*", 100) %>%
gather(key=Type,
value=`Percentage of students`,
-year) %>%
mutate(Estimate = case_when(grepl("_low", Type) ~ "Lower",
grepl("_upp", Type) ~ "Upper",
TRUE ~ "Mean"),
User = case_when(grepl("ever", Type) ~ "Ever",
grepl("current", Type) ~ "Current",
TRUE ~ "Mean")) %>%
dplyr::select(-Type) %>%
spread(Estimate, `Percentage of students`) %>%
ggplot(aes(x=year,y=Mean)) +
geom_line(aes(linetype=User)) +
geom_linerange(aes(ymin = Lower, ymax = Upper)) +
scale_linetype_manual(values = c(2,1)) +
scale_y_continuous(breaks = seq(0,70,by=10),
labels = seq(0,70,by=10),
limits = c(0,70)) +
theme_minimal() +
theme(legend.position = "none",
axis.title.x = element_blank()) +
labs(title = "Nicotine product users becoming increasingly prevalent",
y = "% of students")
plotB_w_8 <- nyts_data %>%
filter((Grade == "8" & year == 2015) |
(Grade == "9" & year == 2016) |
(Grade == "10" & year == 2017) |
(Grade == "11" & year == 2018) |
(Grade == "12" & year == 2019)
) %>%
mutate(ecig_sum_ever = select(., EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
ecig_sum_current = select(., CELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
select(.,-EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
select(.,-CELCIGT) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(ecig_ever = case_when(ecig_sum_ever > 0 ~ TRUE,
ecig_sum_ever ==0 ~ FALSE),
ecig_current = case_when(ecig_sum_current > 0 ~ TRUE,
ecig_sum_current ==0 ~ FALSE),
non_ecig_ever = case_when(non_ecig_sum_ever > 0 ~ TRUE,
non_ecig_sum_ever ==0 ~ FALSE),
non_ecig_current = case_when(non_ecig_sum_current > 0 ~ TRUE,
non_ecig_sum_current ==0 ~ FALSE)) %>%
as_survey_design(strata = stratum, ids = psu, weight = finwgt) %>%
group_by(year) %>%
summarise(ecig_ever_year = survey_mean(ecig_ever, vartype = "ci", na.rm=TRUE),
ecig_current_year = survey_mean(ecig_current, vartype = "ci", na.rm=TRUE),
non_ecig_ever_year = survey_mean(non_ecig_ever, vartype = "ci", na.rm=TRUE),
non_ecig_current_year = survey_mean(non_ecig_current, vartype = "ci", na.rm=TRUE)) %>%
mutate_at(vars(-year), "*", 100) %>%
dplyr::select(year,
ecig_ever_year,
ecig_current_year,
non_ecig_ever_year,
non_ecig_current_year,
contains("low"),
contains("upp")) %>%
gather(key=Category,
value=`Percentage of students`,
-year) %>%
mutate(Estimate = case_when(grepl("_low", Category) ~ "Lower",
grepl("_upp", Category) ~ "Upper",
TRUE ~ "Mean"),
User = case_when(grepl("current", Category) ~ "Current",
TRUE ~ "Ever",),
Product = case_when(grepl("non_ecig", Category) ~ "Other products",
TRUE ~ "E-cigarettes")) %>%
dplyr::select(-Category) %>%
spread(Estimate, `Percentage of students`) %>%
filter(User=="Ever") %>%
dplyr::rename("Lower_temp" = Upper,
"Upper_temp" = Lower) %>%
dplyr::rename("Lower"=Lower_temp,
"Upper"=Upper_temp) %>%
ggplot(aes(x=year,y=Mean, color=Product)) +
geom_line(linetype=1) +
geom_linerange(aes(ymin = Lower, ymax = Upper)) +
scale_y_continuous(breaks = seq(10, 60, by = 10), limits = c(10,60)) +
theme_minimal() +
theme(legend.position = "none",
axis.title.x = element_blank()) +
labs(title = "% ever trying nicotine products increases",
y = "% of students")
plotC_w_8 <- nyts_data %>%
filter((Grade == "8" & year == 2015) |
(Grade == "9" & year == 2016) |
(Grade == "10" & year == 2017) |
(Grade == "11" & year == 2018) |
(Grade == "12" & year == 2019)
) %>%
mutate(ecig_sum_ever = select(., EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
ecig_sum_current = select(., CELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_ever = select(., starts_with("E", ignore.case = FALSE)) %>%
select(.,-EELCIGT) %>%
apply(1, sum, na.rm=TRUE),
non_ecig_sum_current = select(., starts_with("C", ignore.case = FALSE)) %>%
select(.,-CELCIGT) %>%
apply(1, sum, na.rm=TRUE)) %>%
mutate(ecig_ever = case_when(ecig_sum_ever > 0 ~ TRUE,
ecig_sum_ever ==0 ~ FALSE),
ecig_current = case_when(ecig_sum_current > 0 ~ TRUE,
ecig_sum_current ==0 ~ FALSE),
non_ecig_ever = case_when(non_ecig_sum_ever > 0 ~ TRUE,
non_ecig_sum_ever ==0 ~ FALSE),
non_ecig_current = case_when(non_ecig_sum_current > 0 ~ TRUE,
non_ecig_sum_current ==0 ~ FALSE)) %>%
as_survey_design(strata = stratum, ids = psu, weight = finwgt) %>%
group_by(year) %>%
summarise(ecig_ever_year = survey_mean(ecig_ever, vartype = "ci", na.rm=TRUE),
ecig_current_year = survey_mean(ecig_current, vartype = "ci", na.rm=TRUE),
non_ecig_ever_year = survey_mean(non_ecig_ever, vartype = "ci", na.rm=TRUE),
non_ecig_current_year = survey_mean(non_ecig_current, vartype = "ci", na.rm=TRUE)) %>%
mutate_at(vars(-year), "*", 100) %>%
dplyr::select(year,
ecig_ever_year,
ecig_current_year,
non_ecig_ever_year,
non_ecig_current_year,
contains("low"),
contains("upp")) %>%
gather(key=Category,
value=`Percentage of students`,
-year) %>%
mutate(Estimate = case_when(grepl("_low", Category) ~ "Lower",
grepl("_upp", Category) ~ "Upper",
TRUE ~ "Mean"),
User = case_when(grepl("ever", Category) ~ "Ever",
grepl("current", Category) ~ "Current"),
Product = case_when(grepl("non_ecig", Category) ~ "Other products",
TRUE ~ "E-cigarettes")) %>%
dplyr::select(-Category) %>%
spread(Estimate, `Percentage of students`) %>%
ggplot(aes(x=year,y=Mean, color=Product)) +
geom_line(aes(linetype=User)) +
geom_linerange(aes(ymin = Lower, ymax = Upper)) +
scale_linetype_manual(values = c(2,1)) +
scale_y_continuous(breaks = seq(0, 60, by = 10), limits = c(0,60)) +
theme_minimal() +
theme(legend.position = "none",
axis.title.x = element_blank()) +
labs(title = "E-cigarette use surpasses use of other nicotine products",
y = "% of students")
title_w_8 <- ggdraw() +
draw_label(
expression("Among"~8^th~"graders in 2015, have vaping rates possibly influenced tobacco/nicotine use?"),
fontface = 'bold',
size=14,
x = 0,
hjust = 0
) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
plotsA_w_8 <- plot_grid(plotA_w_8,
rel_widths = c(1),
align = "v",
axis = "bt")
plotsBC_w_8 <- plot_grid(plotB_w_8,
plotC_w_8,
rel_widths = c(1,1),
axis = "bt")
legend_w_8 <- get_legend(plotB_w_8 +
theme(legend.position = "bottom",
legend.direction = "horizontal"))
figure_w_8 <- plot_grid(title_w_8,
plotsA_w_8,
plotsBC_w_8,
legend_w_8,
ncol = 1,
rel_heights = c(0.1,
1,
1,
0.1),
scale = 1.0
)
figure_w_8title_final <- ggdraw() +
draw_label(
expression("Have vaping rates possibly influenced tobacco/nicotine use?"),
fontface = 'bold',
size=16,
x = 0.5) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
subtitle_uw_final <- ggdraw() +
draw_label(
expression(~6^th~"-"~12^th~"graders, unweighted"),
size=12,
x = 0.5) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
subtitle_w_final <- ggdraw() +
draw_label(
expression(~6^th~"-"~12^th~"graders, weighted"),
fontface = 'bold',
size=12,
x = 0.5) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
subtitle_w_8_final <- ggdraw() +
draw_label(
expression(~8^th~"graders in 2015, weighted"),
fontface = 'bold',
size=12,
x = 0.5) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
subtitle_final <- plot_grid(subtitle_uw_final,
subtitle_w_final,
subtitle_w_8_final,
ncol = 3)
plotsA_title_final <- ggdraw() +
draw_label(
expression("Prevalence of e-cigarette use by user type"),
size=14,
x = 0.5) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
plotsA_final <- plot_grid(plotA_uw + theme(plot.title = element_blank()),
plotA_w + theme(plot.title = element_blank()),
plotA_w_8 + theme(plot.title = element_blank()),
ncol = 3,
align = "v",
axis = "bt")
plotsB_title_final <- ggdraw() +
draw_label(
expression("Prevalence of ever use by product type"),
size=14,
x = 0.5) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
plotsB_final <- plot_grid(plotB_uw + theme(plot.title = element_blank()),
plotB_w + theme(plot.title = element_blank()),
plotB_w_8 + theme(plot.title = element_blank()),
ncol = 3,
align = "v",
axis = "bt")
plotsC_title_final <- ggdraw() +
draw_label(
expression("Prevalence of nicotine product use by product & user type"),
size=14,
x = 0.5) +
theme(
plot.margin = margin(0, 0, 0, 0)
)
plotsC_final <- plot_grid(plotC_uw + theme(plot.title = element_blank()),
plotC_w + theme(plot.title = element_blank()),
plotC_w_8 + theme(plot.title = element_blank()),
ncol = 3,
align = "v",
axis = "bt")
legend_final <- get_legend(plotB_w +
theme(legend.position = "bottom",
legend.direction = "horizontal"))
final_plot <- plot_grid(title_final,
plotsA_title_final,
subtitle_final,
plotsA_final,
plotsB_title_final,
subtitle_final,
plotsB_final,
plotsC_title_final,
subtitle_final,
plotsC_final,
legend_final,
ncol = 1,
rel_heights = c(0.2,
0.2,
0.1,
1,
0.2,
0.1,
1,
0.2,
0.1,
1,
0.1))
final_plotfinal_plot above for a different cohort of your choice.Ever and current variables are limited to those shared by all years of data included in this case study.
New code: Knit time: 36.582 secs. Previous code: ~ 3 m.
I had difficulty producing a plot that succinctly presented a trend. It’s very easy to produce plots that are very useful once one is familiar with the data. Some plots, however, cannot stand alone and need additional context to be clear for those without prior knowledge of the data. When I first shared a plot I had been working on with others, it became clear that in my effort to present a complicated idea briefly I had left out information that would make the trend easily interpretable. To solve this issue, I began to present visualizations of the data alongside my original plot. The final figure I created contained several additional plots, each presenting the same trend at a different level than my initial plot.
My “centerpiece” plot is the middle plot in final_plot. The 8 plots around it help provide a very clear picture of what is going on in the US with regards to e-cigarette use and nicotine product use at large. On its own, it’s difficult to understand the trends in the US and how important the weighting scheme is for inference. Once you add the left and right columns, it’s clear what is going on.